//1.遍历数据 BufferedReader bis = new BufferedReader(new FileReader("csb.txt")); String b; ArrayList<String>list = new ArrayList<>(); while ((b = bis.readLine()) != null) { list.add(b); } bis.close(); //2.进行排序 Collections.sort(list,new Comparator<String>() { @Override public int compare(String o1, String o2) { int i1 = Integer.parseInt(o1.split("\\.")[0]); int i2 = Integer.parseInt(o2.split("\\.")[0]); return i1-i2; } }); //3.进行拷贝 BufferedWriter bw = new BufferedWriter(new FileWriter("bbb.txt")); //遍历数组 for (String s : list) { //写入 bw.write(s); //换行 bw.newLine(); } bw.close();
出师表排序1
最新推荐文章于 2024-08-18 23:41:46 发布