package com;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class FileIO {
public static void main(String[] args) throws IOException {
File file = new File("R:\\haha2.txt");//读取文件haha2.txt
File file2 = new File("R:\\haha.txt");//读取文件haha.txt
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(file2)));//用BufferedReader读取文件流
String line;
FileOutputStream fs = null;
while ((line = br.readLine()) != null) {//一次 读取 一行内容
if (file.exists()) {
fs = new FileOutputStream(file,true);//=====加上 true=====
fs.write(line.getBytes());
} else {
file.createNewFile();//创建 文件 txt
}
}
fs.flush();
fs.close();
br.close();
}
}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class FileIO {
}