嗯,这个是代码- package Mianshi;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Set;
- import java.util.TreeMap;
- public class Mianshi2 {
- public static void main(String[] args) throws IOException {
-
- BufferedReader bufr=new BufferedReader(new InputStreamReader(System.in));
- BufferedWriter bufw=new BufferedWriter(new FileWriter("C:\\Users\\huang\\Desktop\\stu.txt"));
- TreeMap<String,Integer>tm=new TreeMap<String,Integer>();
-
- String line=null;
- while((line=bufr.readLine())!=null)
- {
- if("over".equals(line))
- break;
- String str[]=line.split(",");
- tm.put(str[0], Integer.parseInt(str[1]));
- }
- Set<String>keySet=tm.keySet();
- java.util.Iterator<String> it=keySet.iterator();
- while(it.hasNext())
- {
- String key=it.next();
- Integer value=tm.get(key);
- bufw.write(key+","+value);
- bufw.newLine();
- }
- bufw.close();
- bufr.close();
-
- }
- }
复制代码
|