do{
newTops.add(new String(readNewTop()));
}while (!end(readNewTop()));
用于判断和你add进去的不是同一个值 readNewTop()执行了两次
readNewTop()应该赋给一个变量,对变量操作
package cn.com.xxx; //根据实际情况调整
import java.io.*;
public class ReadWriteFile {
public static void printFile(String name) throws Exception {
FileReader fin = new FileReader(name);
int temp;
while ((temp = fin.read()) != -1)
System.out.print((char) temp);
System.out.println();
fin.close();
}
public static void mergeFile(String one, String two, String result)
throws Exception {
FileReader fin1 = new FileReader(one);
FileReader fin2 = new FileReader(two);
PrintWriter out = new PrintWriter(result);
int temp1, temp2;
while ((temp1 = fin1.read()) != -1)
out.print((char) temp1);
out.println();
while ((temp2 = fin2.read()) != -1)
out.append((char) temp2);
out.close();
fin1.close();
fin2.close();
}
public static void main(String[] args) {
try {
printFile("D:\\Test\\1.txt"); //文件路径根据实际情况调整下同
printFile("D:\\Test\\2.txt");
mergeFile("D:\\Test\\1.txt", "D:\\Test\\2.txt", "D:\\Test\\3.txt");
} catch (Exception e) {
e.printStackTrace();
}
}
}
如果对您有帮助,请记得采纳为满意答案,谢谢!祝您生活愉快!
vaela