标签:reader ade 刷新数据 sub eem 编号 substr 不为 try
/*
2.何事秋风悲画扇
4.却道故人心易变
1.人生若只如初见
3.等闲变却故人心
请按照顺序排列并且写道文件b.txt中
*/
public class Six {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("20190815\\a.txt"));
TreeMap<Integer,String> tm = new TreeMap<>();
String line;
while((line = br.readLine()) != null){//字符串等于,文件读取行数到不为Null为止
String num = line.substring(0,1);//截取前面的编号
tm.put(Integer.parseInt(num),line);
}
br.close();//关闭读取的流
BufferedWriter bw = new BufferedWriter(new FileWriter("20190815\\b.txt"));
Set<Map.Entry<Integer, String>> entries = tm.entrySet();
for (Map.Entry<Integer, String> entry : entries) {
bw.write(entry.getValue());//获取集合的值
bw.newLine();//一行一行的写入,的分割符
bw.flush();//刷新数据
}
bw.close();
}
}
标签:reader ade 刷新数据 sub eem 编号 substr 不为 try
原文地址:https://www.cnblogs.com/YRSWBY2016/p/12019501.html