黑马程序员技术交流社区

标题: 泛型IO应用 [打印本页]

作者: 李娟    时间: 2011-12-23 23:37
标题: 泛型IO应用
本帖最后由 李娟 于 2011-12-24 09:16 编辑

while((line=bufr.readLine())!=null)
                {
                        if("over".equals(line))
                                break;
                        String[] info = line.split(",");
                        String stu = new Student(info[0],Integer.parseInt(info[1]),
                                Integer.parseInt(info[2]),
                                Integer.parseInt(info[3]));
                        stus.add(stu);
                }
                bufr.close();
                return stus;
        }
        public static void write2File(Set<Student> stus)throws IOException
        {
                BufferedWriter bufw = new BufferedWriter(new FileWriter("stuinfo.txt"));
                for(Student stu:stus)
                {
                        bufw.write(stu.toString()+"\t");
                        bufw.write(stu.getSum()+"");
                        bufw.newLine();
                        bufw.flush();
                }
                bufw.close();
        }
}
class StudentInfoTest
{
        public static void main(String[] args) throws IOException
        {
                Comparator<Student> cmp = Collection.reverseOrder();
                Set<Student> stus = StudentInfoTool.getStudents();
                StudentInfoTool.write2File(stus);
        }
}

作者: 黑马巩伟伟    时间: 2011-12-24 00:00
  String stu = new Student(info[0],Integer.parseInt(info[1]),
这里用String去接收Student对象似乎有点不妥。你应该是把Strudent错写为String了。
找不到符号的原因,你看看有没有写错对象名,或者方法名。如果确定这两个都没错,那就再看看有没有导入运行时需要的包。应该是需要java.util.*;




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2