大神们给我看看下面我这个方法哪里错了?为什么总是移动文件失败!
下面是输出打印的两句路径:
/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;
}
}