package four.day;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Set;
public class demoStudent {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Set<students> stus = studenttool.getstudents();
System.out.println("键盘录录完毕!!");
studenttool.writeStu(stus);
}
}
class students
{
String name;
int ma,en,cn;;
int sum=0;
students(String name,int ma,int en,int cn )
{
this.name=name;
this.ma=ma;
this.en=en;
this.cn=cn;
sum=ma+en+cn;
}
public int getsum()
{
return sum;
}
public String getname()
{
return name;
}
public String toString()
{
return "Student["+name+","+ma+","+en+","+cn+",]";
}
}
class studenttool
{
public static Set<students> getstudents() throws Exception, IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Set<students> stu=null;
String line=null;
while((line=br.readLine())!=null)
{
if(line.equals("over"))
{
break;
}
String info[]=line.split(",");
students s=new students(info[0],Integer.parseInt(info[1]),Integer.parseInt(info[1]),Integer.parseInt(info[1]));
stu.add(s);
}
for(students s:stu)
{
System.out.println(s.toString());
}
return stu;
}
public static void writeStu(Set<students> stu) throws IOException
{
BufferedWriter bw=new BufferedWriter(new FileWriter("g:/java/java基础4/stu.txt"));
for(students s:stu)
{
bw.write(s.toString());
bw.newLine();
}
bw.close();
}
}
为什么studenttool.getstudents(); 老抛出空指针、、 |