public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new FileReader("file1.txt"));
String str;
int count=0;
double max=0;
double min=100;
double sum=0;
double avg;
while((str=br.readLine().trim())!=null){
count++;
double d=Double.parseDouble(str.split(" ")[1]);
if(max<=d){
max=d;
}
if(min>=d){
min=d;
}
sum=sum+d;
}
avg=sum/count;
PrintWriter pw=new PrintWriter(new OutputStreamWriter(new FileOutputStream(new File("file2.txt"))));
pw.println("最高分:"+max+"\n"+"最低分:"+min+"\n"+"平均分:"+avg);
pw.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
file1.txt中的数据是以姓名+空格+成绩的形式存储的