将文件上传到Web服务器时文件未找到异常?

时间:2010-07-19 14:08:08

标签: android

我正在使用以下tutorial将图片文件上传到网络服务器。

并在此处获取文件未找到异常。

try {
         File uploadFile = new File(uriString); 

// file path i receive **content:/media/external/images/media/2**

        FileInputStream fis =   this.openFileInput(uploadFile.getName()); // **ERRoR HERE**

        HttpFileUploader htfu = new HttpFileUploader("http://finditnear.sigmatec.com.pk/inbox/send_remote_reply","noparamshere", uploadFile.getName());
        htfu.doStart(fis);
        } 
    catch (FileNotFoundException e) {
        Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
        e.printStackTrace();
        return;
        }

图像文件存在,但它仍然给我错误。

任何人都可以指导我解决方案吗?

2 个答案:

答案 0 :(得分:2)

内容:/ media / external / images / media / 2是不正确的文件名,它是一个Uri 所以这一行

FileInputStream fis =   this.openFileInput(uploadFile.getName());

应替换为

InputStream fis=this.getContentResolver().openInputStream(new Uri(uriString));

答案 1 :(得分:0)

你添加了:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

到你的AndroidManifest