对于我的应用,我正在将文件从Source复制到Destination文件夹以进行进一步的图像处理。我 尝试将jpg文件从src复制到dst文件夹。该 函数似乎工作,但我仍然得到此IOException错误。 谁能解释为什么close()会失败?
public static void copyPicture(String src, String dst) {
File pic = null;
File newPic = null;
pic = new File(src);
newPic = new File(dst);
FileChannel srcChannel = null;
FileChannel dstChannel = null;
try {
srcChannel = new FileInputStream(pic).getChannel();
dstChannel = new FileOutputStream(newPic).getChannel();
dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if(dstChannel != null) {
dstChannel.close();
}
srcChannel.close();
} catch (IOException e) {
e.printStackTrace();
}
srcChannel = null;
dstChannel = null;
src = null;
dst = null;
}
}
目录下载:
07-04 21:43:15.330: E/System(28070): Uncaught exception thrown by finalizer
07-04 21:43:15.330: E/System(28070): java.io.IOException: close failed: EIO (I/O error)
07-04 21:43:15.330: E/System(28070): at libcore.io.IoUtils.close(IoUtils.java:41)
07-04 21:43:15.330: E/System(28070): at java.io.FileOutputStream.close(FileOutputStream.java:139)
07-04 21:43:15.330: E/System(28070): at java.io.FileOutputStream.finalize(FileOutputStream.java:153)
07-04 21:43:15.330: E/System(28070): at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:186)
07-04 21:43:15.330: E/System(28070): at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:169)
07-04 21:43:15.330: E/System(28070): at java.lang.Thread.run(Thread.java:856)
07-04 21:43:15.330: E/System(28070): Caused by: libcore.io.ErrnoException: close failed: EIO (I/O error)
07-04 21:43:15.330: E/System(28070): at libcore.io.Posix.close(Native Method)
07-04 21:43:15.330: E/System(28070): at libcore.io.BlockGuardOs.close(BlockGuardOs.java:75)
07-04 21:43:15.330: E/System(28070): at libcore.io.IoUtils.close(IoUtils.java:38)