私のアプリケーションには、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);
なぜそれが機能しないのですか?