大神們給我看看下面我這個方法哪裡錯了?為什麼總是移動文件失敗!
下面是輸出打印的兩句路徑:
/storage/sdcard0/dcim/Camera/IMG_20151127_094856.jpg
/storage/sdcard0/baidu/searchbox/preset/preset4.2/pic/
/**
* 移動至指定文件夾
* @param path
* @param newPath
* @return
*/
public static boolean updateToFolder(String path, String newPath) {
Log.e("==path==>>>", path);
Log.e("==path==>>>", newPath);
File oldfile = new File(path);
if (!oldfile.exists()) {
return false;
}
File newfile = new File(newPath);
if (!newfile.exists()) {
return false;
}
int byteread = 0;
try {
InputStream ipStream = new FileInputStream(oldfile); // 讀入原文件
OutputStream opStream = new FileOutputStream(newfile);
byte[] buffer = new byte[1024];
while ((byteread = ipStream.read(buffer)) != -1) {
opStream.write(buffer, 0, byteread);
}
ipStream.close();
opStream.close();
oldfile.delete();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
原路徑:/storage/sdcard0/dcim/Camera/a2051958524f8b085262c960866397ce.jpg
目標文件夾:/storage/sdcard0/baidu/searchbox/preset/preset4.2/pic/
最終路徑:/storage/sdcard0/baidu/searchbox/preset/preset4.2/pic/a2051958524f8b085262c960866397ce.jpg
我這樣加了,還是不行呀!代碼沒拋異常,但是圖片沒移動過去,而且源圖片還變沒了。