java合并两个文件

package program;

 

import java.io.File;

import java.io.IOException;

import java.util.Collections;

import java.util.List;

 

import org.apache.commons.io.FileUtils;

 

public class Tele {

 

private static final String CURRENTFILE = "c:/test/current.txt";

private static final String TODAYFILE = "c:/test/today.txt";

private static final String RESULTFILE = "c:/test/result.txt";

 

public static void main(String[] args){

 

try {

List<String> currentNum = FileUtils.readLines(new File(CURRENTFILE), "UTF-8");

List<String> todayNum = FileUtils.readLines(new File(TODAYFILE), "UTF-8");

currentNum.addAll(todayNum);

Collections.sort(currentNum);

System.out.println(currentNum.toArray().length);

FileUtils.writeLines(new File(RESULTFILE), currentNum);

} catch (IOException e) {

new Exception("读取文件时出错");

}

}

}


把当前文件的记录 加入到总记录中,并排序

你可能感兴趣的:(java)