问题是否全部适用于图像(由相机或其他方式拍摄) 但实际上不适用于Whatsapp图片。实际上,它正在复制文件,但我正在检查复制的图像是否损坏,如果有人解决了此问题,将不胜感激,谢谢。
这是我在整理目标文件和源文件,并调用 copyFileUsingStream 函数
List<Image> images = ImagePicker.getImages(data);
File f1 = new File(images.get(0).getPath());
File directory = new File(Environment.getExternalStorageDirectory(), "mommyTemp");
if (!directory.exists())
directory.mkdirs();
File f = new File(directory, "temp.jpg");
try {
copyFileUsingStream(f1, f);
} catch (IOException e) {
e.printStackTrace();
}
这是我的复制功能
private static void copyFileUsingStream(File source, File dest) throws IOException {
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(source);
os = new FileOutputStream(dest);
BufferedInputStream bin = new BufferedInputStream(is);
BufferedOutputStream bou = new BufferedOutputStream(os);
int b = 0;
while (b != -1) {
b = bin.read();
bou.write(b);
}
} finally {
is.close();
os.close();
}
}