0
FTP 서버에서 파일을 다운로드해야하는 android 용 앱을 작성하고 있습니다. FTP 서버에서 문제없이 파일을 읽을 수있는 것 같지만 파일을 열려고하면 해당 파일 이름이나 디렉토리가 없습니다.Android : 해당 파일 이름 또는 디렉토리 없음
코드 :
FTPClient ftp = new FTPClient ; // The ftpclient of apache commons
// all the code for connecting to the server
FileOutputStream fOut = openFileOutput("ipfile.text" , Context.MODE_WORLD_WRITEABLE) ;
ftp.retrieveFile("ip.text" , fOut) ;
Log.v("As" , "Read file with succes from drivehq") ;
String helpStr = "ERROR" ;
byte[] inputBuffer = new byte [1024] ;
try{
FileInputStream fis = new FileInputStream("/data/data/ipfile.text") ;
fis.read(inputBuffer) ;
fis.close() ;
helpStr = new String (inputBuffer) ;
Log.v("As" , "Read file from " + helpStr) ;
}
catch(Exception e) {
Log.v("As" ," Unable to read the ip-file " + e.getMessage()) ;
}
로그 캣 :
02-28 21:31:38.741: V/As(3992): Logged on with success to drivehq
02-28 21:31:38.911: V/As(3992): Changed working directory on drivehq
02-28 21:31:39.972: V/As(3992): Read file with succes from drivehq
02-28 21:31:39.972: V/As(3992): Unable to read the ip-file ipfile.text (No such file or directory)
감사합니다, 톰
고마워요! 그것은 참으로 마지막 이유였습니다 :) – tb96
훌륭합니다! 첫 번째 부분을 잊지 마라! 출력 스트림이 끝나면 출력 스트림을 닫으려고합니다. openFileOutput은 응용 프로그램 사설 컨텍스트 파일에 대한 액세스를 제공합니다. FileInputStream ("/ data/data/ipfile.text")을 사용하면 기본적으로 그 방법으로 파일을 열 수있는 권한이 없기 때문에 작동하지 않습니다. – dymmeh
좋아요, 그 점을 명심하십시오! – tb96