java.io.FileNotFoundException:/file/path.jpg打开失败:ENOENT(没有这样的文件或目录)

Cha*_*ham 4 android bytearray inputstream apache-commons parse-platform

我正在尝试将图像保存到parse.com.我需要将其转换为字节数组.我决定尝试这样做的方法是使用apache commons-io.它运作不正常.这是我的代码片段;

private void saveImage() throws IOException {
    // TODO Auto-generated method stub

    InputStream header = new FileInputStream("/ClashMMA/res/drawable-hdpi/beatdown.jpg");

    ParseFile file = new ParseFile(toByteArray(header));
    try{
        file.save();
    } catch (ParseException e) {
        e.printStackTrace();
    }

    ParseObject displayImage = new ParseObject("displayImage");
    displayImage.put("header", file);
    try{
        displayImage.save();
    } catch (ParseException e1){
        e1.printStackTrace();
    }
}


private byte[] toByteArray(InputStream header) throws IOException {
    // TODO Auto-generated method stub
     ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        int l;
        byte[] data = new byte[1024];
        while ((l = header.read(data, 0, data.length)) != -1) {
          buffer.write(data, 0, l);
        }
        buffer.flush();
        return buffer.toByteArray();

}
Run Code Online (Sandbox Code Playgroud)

而我的错误是这样的;

java.io.FileNotFoundException: /ClashMMA/res/drawable-hdpi/beatdown.jpg: open failed: ENOENT (No such file or directory)

但我确信该文件存在,因为我去了我的文件目录(在eclipse中),右键单击,然后单击Copy Qualified Name.这基本上复制了文件路径.我尝试过其他一些路径,比如我的电脑和我的src文件夹.有人可以告诉我我做错了什么吗?为什么它不会读取文件,实际上它在那里?详细解释请.

Ste*_*n C 5

Eclipse项目中的文件不在(真实的或模拟的)Android文件系统中,这就是Android所在的FileInputStream位置.(有充分的理由!Eclipse的主机文件系统不会出现在真正的Android设备上.)

你基本上有两个选择: