繁体   English   中英

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

[英]java.io.FileNotFoundException: /file/path.jpg open failed: ENOENT (No such file or directory)

我正在尝试将图像保存到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();

}

而我的错误是这样的;

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

但我确信文件在那里,因为我去了我的文件目录(在eclipse中),右键单击,然后单击Copy Qualified Name 这基本上复制了文件路径。 我已经尝试了一些其他路径,例如关闭我的计算机,以及我的src文件夹。 有人可以告诉我我做错了什么吗? 为什么它不会读取文件,实际上它在那里? 详细解释请。

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

你基本上有两个选择:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM