// 测试复制文件
@Test
public void copyFile() throws Exception {
String srcPath="D:/qqqq.jpg";
String destPath="D:/copyqqqq.jpg";
InputStream input=null;
File srcFile=new File(srcPath);
if(srcFile.exists()){
input = new FileInputStream(srcFile);
writeToLocal(input, destPath);
}
else{
System.out.println("文件不存在........");
return;
}
}
public static void writeToLocal(InputStream in, String destPath) {
FileOutputStream out = null;
int b = 0;
try {
out = new FileOutputStream(destPath);
while ((b = in.read()) != -1) {
out.write(b);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
in.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
java复制文件
最新推荐文章于 2024-01-18 18:35:08 发布