내 응용 프로그램은 PHP 스크립트에 업로드 된 파일을 선택하도록 사용자에게 요청합니다. 사용자가 파일을 선택하면 올바른 URI가 반환되지만 파일에 액세스하려고하면 FileNotFound 오류가 발생합니다.안드로이드에서 파일을 읽고 업로드하는 중 오류가 발생했습니다.
private static final int FILE_SELECT_CODE = 1234;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
Log.d("file upload register page", "File Uri: " + uri.toString());
try {
file_path = FileUtils.getPath(getBaseContext(), uri);
}
catch (URISyntaxException e) {
e.printStackTrace();
}
Log.d("file upload register page", "File Path: " + file_path);
file = new File(file_path);
UploadFile task = new UploadFile();
task.execute();
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
FileUtils.getPath 함수는 지정된 URI에 대한 경로를 반환 : 다음은 onActivityResult를 코드입니다. 로그에 따르면 반환 된 경로는 다음과 같습니다. file : ///mnt/sdcard/bluetooth/Tutorial%201.pdf
AsyncTask UploadFile에서 파일을 원격 서버에 업로드하고 있습니다.
public void newUpload()
{
HttpEntity resEntity;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(file), -1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(true); // Send in multiple parts if needed
httppost.setEntity(reqEntity);
HttpResponse response_http = httpclient.execute(httppost);
//Do something with response...
resEntity = response_http.getEntity();
response = EntityUtils.toString(resEntity);
Log.d("response",response);
}
catch (Exception e) {
e.printStackTrace();
}
}
가 어떻게 예외를 찾을 수없는 파일을 해결 않습니다 나는 오류 이것은 내가 파일을 업로드하는 방법입니다
java.io.FileNotFoundException: /file:/mnt/sdcard/bluetooth/Tutorial%201.pdf (No such file or directory).
을 얻을? 나는 그것이 작동하지 않는 이유를 전혀 모른다!
'new FileInputStream (file)'을 할 때,'file'의 정확한 값은 무엇입니까? 나는/file :/mnt/sdcard/bluetooth/Tutorial % 201.pdf의 –