Hi,
i want to make mini-school project and so i create 3 class(School,Student and Run) i want to write students name out.txt with using bufferedwriter but i can't do it.
School Class Code;
import java.util.*; public class School { private int schoolId; private String schoolName; public int getSchoolId() { return schoolId; } public School(int schoolId, String schoolName) { super(); this.schoolId = schoolId; this.schoolName = schoolName; } public void setSchoolId(int schoolId) { this.schoolId = schoolId; } public String getSchoolName() { return schoolName; } public void setSchoolName(String schoolName) { this.schoolName = schoolName; } public List<Student> getStudents() { return students; } public void setStudents(List<Student> students) { this.students = students; } public List<Student> students; }
Student Class Code;
public class Student { private int studentId; private String studentName; public int getStudentId() { return studentId; } public Student(int studentId, String studentName) { super(); this.studentId = studentId; this.studentName = studentName; } public void setStudentId(int studentId) { this.studentId = studentId; } public String getStudentName() { return studentName; } public void setStudentName(String studentName) { this.studentName = studentName; } public School getSchool() { return school; } public void setSchool(School school) { this.school = school; } private School school; }
and Run Class Code;
public static void main(String[] args) { // TODO Auto-generated method stub School sc = new School(1, "Berkeley"); sc.setStudents(new ArrayList<Student>()); Student st1 = new Student(1,"Bill Gates"); st1.setSchool(sc); sc.getStudents().add(st1); Student st2 = new Student(2,"Steve Jobs"); st2.setSchool(sc); sc.getStudents().add(st2); Student st3 = new Student(3,"Larry Page"); st3.setSchool(sc); sc.getStudents().add(st3); try { String file="d:\\okul\\out.txt"; FileWriter fw = new FileWriter(file,true); BufferedWriter bw = new BufferedWriter(fw); List<Student> t=sc.getStudents(); bw.write(t); bw.close(); }catch(Exception e){ e.printStackTrace(); } } }
but line of "bw.write(t)" said problem.
"The method write(int) in the type BufferedWriter is not applicable for the arguments (List<Student>)"
how can i correnting this problem ?
thanx.