代码:
import java.io.*;
import java.util.Arrays;
public class Test {
public static void main(String[] args) throws IOException {
readFileSortToNewFile();
}
private static void readFileSortToNewFile() throws IOException {
readFileSortToNewFile(new File("D:\\ESD\\a.txt"),new File("D:\\ESD\\b.txt"));
}
private static void readFileSortToNewFile(File src, File target) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(src));
BufferedWriter bw = new BufferedWriter(new FileWriter(target));
int len = -1;
char[] buf = new char[1024];
StringBuilder sb = new StringBuilder();
while ((len = br.read(buf)) != -1) {
sb.append(new String(buf, 0, len));
}
char[] chars = sb.toString().toCharArray();
Arrays.sort(chars);
bw.write(new String(chars));
bw.close();br.close();
}
}