[英]Android: open failed: ENOENT No such file or directory
I know have many question like my question. 我知道有很多问题,例如我的问题。 But It is different. 但这是不同的。 I copy file from folder A to folder B in EXTERNAL_STORAGE
use mothod below: 我使用下面的方法将文件从文件夹A复制到EXTERNAL_STORAGE
文件夹B:
public static String copyFile(String path) {
String fileToName = String.valueOf(System.currentTimeMillis());
File pathFrom = new File(path);
File pathTo = new File(Environment.getExternalStorageDirectory() + "/.noname");
File file = new File(pathTo, fileToName + ".bak");
while (file.exists()) {
fileToName = String.valueOf(System.currentTimeMillis());
file = new File(pathTo, fileToName + ".bak");
}
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(pathFrom);
out = new FileOutputStream(file);
byte[] data = new byte[in.available()];
in.read(data);
out.write(data);
in.close();
out.close();
} catch (FileNotFoundException e) {
Log.e(TAG, e.getMessage());
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
return file.getPath();
}
The path param is: "/storage/emulated/0/Download/image_preview.jpg". 路径参数为:“ / storage / emulated / 0 / Download / image_preview.jpg”。 When execute this method I got an error: /storage/emulated/0/Download/tree_leaves_sunlight.jpg: open failed: ENOENT (No such file or directory)
. 执行此方法时,出现错误: /storage/emulated/0/Download/tree_leaves_sunlight.jpg: open failed: ENOENT (No such file or directory)
。 Folder .noname
have exists. 文件夹.noname
存在。 Is there any suggestion for my problem? 对我的问题有什么建议吗?
**UPDATE: This file I opening with ImageView
. **更新:我使用ImageView
打开此文件。 When I not open I can copy. 当我不打开时,我可以复制。 But When I opening I got this error. 但是当我打开我得到这个错误。 PS: I preview the image in ImageView
. PS:我在ImageView
预览图像。 And there have a Button
copy image. 并有一个Button
复制图像。 When click to Button execute method copy this image to other folder. 当单击“按钮”执行方法时,将此图像复制到其他文件夹。
When you create the File object for the parent directory File pathTo = new File(Environment.getExternalStorageDirectory() + "/.noname")
Don't forget to actually create this folder 为父目录创建File对象时File pathTo = new File(Environment.getExternalStorageDirectory() + "/.noname")
不要忘记实际创建此文件夹
pathTo.mkdirs();
Also try to open file you're trying to copy in the gallery. 另外,尝试打开您要在图库中复制的文件。 It can be damaged and Android just can't open it. 它可能会损坏,而Android无法打开它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.