为什么总是移动文件失败!
下面是输出打印的两句路径:
/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
我这样加了,还是不行呀!代码没抛异常,但是图片没移动过去,而且源图片还变没了。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。