import java.io.*;
/**
* @Description: 复制文件,从一个输入流中读取数据,然后通过输出流写入目标位置,一边读一边写
* @ClassName: CopyFile
* @Version: V1.0
*/
public class CopyFile {
private static void copy(String src, String target) {
File srcFile = new File(src);
File targetFile = new File(target);
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(srcFile);
out = new FileOutputStream(targetFile);
byte[] b = new byte[1024];
int len = -1;
while ((len = in.read(b)) != -1) {
out.write(b, 0, len);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (in != null)
in.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
java文件操作报错:java.io.FileNotFoundException:D..(拒绝访问)
最新推荐文章于 2023-11-04 13:36:01 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)