1
在我的Android應用程序中,我想將媒體圖像複製到另一個文件夾(在我的下面的代碼中,我嘗試將圖片從「/mnt/sdcard/DCIM/Camera/my_photo.jpg」複製到「/ mnt/sdcard/PortFolio/MyGallery /。我試圖與下面的代碼,但它不工作。有人幫我出這???是有可能嗎?任何其他方式Android如何將媒體圖片移動到其他文件夾?
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
if (sd.canWrite()) {
String sourceImagePath= "/mnt/sdcard/DCIM/Camera/my_photo.jpg";
String destinationImagePath= "/mnt/sdcard/PortFolio/MyGallery/";
Log.d("destinationImagePath", ""+destinationImagePath);
File source= new File(data, sourceImagePath);
File destination= new File(sd, destinationImagePath);
Log.d("before copying", "");
if (source.exists()) {
FileChannel src = new FileInputStream(source).getChannel();
FileChannel dst = new FileOutputStream(destination).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}