字节流
FileInputStream fis = new FileInputStream(sf); FileOutputStream fos = new FileOutputStream(df);
字符流
Reader reader = new FileReader(sf); Writer writer = new FileWriter(df);
缓冲流
BufferedReader reader = new BufferedReader(new FileReader(sf)); BufferedWriter writer = new BufferedWriter(new FileWriter(df));
以字节流为例
//将b.txt中的内容写进a.txt
String sf = "b.txt";
String df = "a.txt";
FileInputStream fis = new FileInputStream(sf);
FileOutputStream fos = new FileOutputStream(df);
byte[] bytes = new byte[1024];
int len;
while ((len = fis.read(bytes)) != -1) {
fos.write(bytes, 0, len);
}
fis.close();
fos.close();