public class ReadAndWrite {
public static void main(String[] args) throws Exception{
List<String> lines = new ArrayList<String>();
FileWriter fw = new FileWriter("./file/2.txt",false);
BufferedWriter bw = new BufferedWriter(fw);
FileReader fr = new FileReader("./file/1.txt");
BufferedReader br = new BufferedReader(fr);
String temp = null;
//read and write
while((temp = br.readLine()) != null){
System.out.println(temp);
lines.add(temp);
bw.write(temp);
bw.newLine();
bw.flush();
}
fw.close();
br.close();
for(String line : lines){
String[] columns = line.split("\t");
System.out.println(columns[0] + "\t"+columns[1]+"\t"+columns[2]+"\t"+columns[3]);
}
}
}
文件1.txt 文件2.txt如附件
public static void main(String[] args) throws Exception{
List<String> lines = new ArrayList<String>();
FileWriter fw = new FileWriter("./file/2.txt",false);
BufferedWriter bw = new BufferedWriter(fw);
FileReader fr = new FileReader("./file/1.txt");
BufferedReader br = new BufferedReader(fr);
String temp = null;
//read and write
while((temp = br.readLine()) != null){
System.out.println(temp);
lines.add(temp);
bw.write(temp);
bw.newLine();
bw.flush();
}
fw.close();
br.close();
for(String line : lines){
String[] columns = line.split("\t");
System.out.println(columns[0] + "\t"+columns[1]+"\t"+columns[2]+"\t"+columns[3]);
}
}
}
文件1.txt 文件2.txt如附件