用流
import java.io.*;
public class TestFileWriter {
public static void main(String[] args) {
FileReader fr = null;
FileWriter fw = null;
int b = 0;
char[] cbuf = new char[18];
try {
fr = new FileReader("E:\\java\\io\\1.txt");//1.txt保存的位置
fw = new FileWriter("E:\\java\\io\\2.txt");//2.txt保存的位置
while ((b=fr.read(cbuf,0,18))!=-1) {
fw.write(cbuf,0,18);
}
}
catch(FileNotFoundException e) {
e.getMessage();
e.printStackTrace();
}
catch(IOException e) {
e.getMessage();
e.printStackTrace();
}
finally {
try {
fr.close();
fw.close();
} catch(IOException e) {
e.getMessage();
e.printStackTrace();
}
}
}
}