package com.tedu.day1201;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class CopyFile {
public static void main(String[] args) {
FileInputStream in= null;
FileOutputStream out =null;
String source = "test.txt";
String tar = "test3.txt";
try {
in = new FileInputStream(source);
out = new FileOutputStream(tar);
int data;
while ((data=in.read())!=-1){
out.write(data);
}
in.close();
out.close();
System.out.println("文件复制陈宫了");
}catch (Exception e){
e.printStackTrace();
}finally {
try {
in.close(); // 可能出现IOException
out.close();
}catch (Exception e){
e.printStackTrace();
}
}
}
}
标签:java,String,复制,FileOutputStream,IO,close,FileInputStream,out
From: https://www.cnblogs.com/ch2020/p/16860973.html