我的应用程序中有一个功能,可以在我的数据库中保存一个 doc/img 文件路径。该文件位于一个文件夹中(例如“/mnt/sdcard/MyApp/MyItem/test.png”)。现在我要做的是将此文件复制到其他文件夹(例如/mnt/sdcard/MyApp/MyItem/Today/test.png)。
现在我正在使用下面的代码,但它不起作用:
private void copyDirectory(File from, File to) throws IOException {
try {
int bytesum = 0;
int byteread = 0;
InputStream inStream = new FileInputStream(from);
FileOutputStream fs = new FileOutputStream(to);
byte[] buffer = new byte[1444];
while ((byteread = inStream.read(buffer)) != -1) {
bytesum += byteread;
fs.write(buffer, 0, byteread);
}
inStream.close();
fs.close();
} catch (Exception e) {
}
}
并使用以下代码单击按钮:
File sourceFile = new File(fileList.get(0).getAbsolutePath); //comes from dbs
File targetFile = new File(Environment.getExternalStorageDirectory(),"MyApp/MyItem/Today/");
copyDirectory(sourceFile,targetFile, currDateStr);
知道为什么它不起作用吗?