将文档的内容排序:
public static void main(String[] args) throws IOException {File dir = new File("J:\\360downloads\\wpcache\\srvsetwp\\xxx\\test.txt");BufferedReader br = new BufferedReader(new FileReader(dir));//把按行读取到的内容,把文件中所有行分别放到ArrayList中ArrayList<String> list = new ArrayList<>();while (true){String line = br.readLine();if (line == null){break;}list.add(line);}//关闭流br.close();//按照首行第一个字符大小重新排序,调用Arraylist自带的排序方法list.sort((o1, o2) -> o1.charAt(0) - o2.charAt(0));//将排好的顺序写入到文件中BufferedWriter bw = new BufferedWriter(new FileWriter(dir));for (String s : list) {bw.write(s);bw.newLine();}//关闭流bw.close();}