import *;
public class Dong{
public static void main(String[] args) throws IOException
{
int m=0;
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new FileWriter("d:\\a.txt"));
String s;
while(true){
System.out.println("输入班级");
s=br.readLine();
if(s.length()==0) break;
bw.write(s);
bw.newLine();System.out.println("输入姓名");
s=br.readLine();
bw.write(s);
bw.newLine();
System.out.println("输入成绩");
s=br.readLine();
bw.write(s);
bw.newLine();
m=m+1;
}
br.close();
bw.close();
String a[]=new String[m];
int d[]=new int[m];
int b[]=new int[m];
int c[]=new int[m];
BufferedReader bf=new BufferedReader(new FileReader("d:\\a.txt"));
int j=0;
while(true){
String ss=bf.readLine();
if(ss==null)
break;
int greade1=Integer.parseInt(ss);
d[j]=greade1;
ss=bf.readLine();
a[j]=ss;
ss=bf.readLine();
int greade=Integer.parseInt(ss);
b[j]=greade;
j++;
}
bf.close();
BufferedWriter bw1=new BufferedWriter(new FileWriter("d:\\b.txt"));
BufferedWriter br1=new BufferedWriter(new OutputStreamWriter(System.out));
int k,t,f,n;
for(int i=0;i<j-1;i++){
c[i]=i;
}
for(int i=0;i<a.length-1;i++){
k=i;
for(n=i+1;n<a.length;n++){
if (b[n]<b[k]){
k=n;
t=b[i];
b[i]=b[k];
b[k]=t;
f=c[i];
c[i]=c[k];
c[k]=f;
}
}
}
for(int x=0;x<c.length;x++){
bw1.write(String.valueOf(d[c[x]]+","+a[c[x]]+","+b[x]));
br1.write(String.valueOf(d[c[x]]+","+a[c[x]]+","+b[x]));
bw1.newLine();
br1.newLine();
}
bw1.close();
br1.close();
}
catch (FileNotFoundException fe)
{ System.out.println(fe.toString());}
catch (IOException ie)
{ System.out.println(ie.toString());}
}
}
源程序