public class CopyReaderAndWriter {
public static void main(String[] args) {
try {
FileInputStream fileInputStream = new FileInputStream("learn.txt");
//把字节流转化成字符流
InputStreamReader isr = new InputStreamReader(fileInputStream);
//public FileOutputStream(String name, boolean append)代表append可接字符串
FileOutputStream fileOutputStream = new FileOutputStream("learn2.txt",true);
//把字节流转化成字符流
OutputStreamWriter osw = new OutputStreamWriter(fileOutputStream);
char c [] = new char[1024];
int l = 0;
while ((l = isr.read(c)) != -1) {
osw.write(new String(c,0,l));
}
isr.close();
fileInputStream.close();
osw.close();
fileInputStream.close();
System.out.println("done");
} catch (Exception e) {
e.printStackTrace();
}
}
}
网友评论