java手把手教你写代码 java代码怎么写( 五 )


File filename = new File(pathname); // 要读取以上路径的txt文件
ListCourse list = new ArrayListCourse();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(filename));
//读取文件内容
byte[] b = new byte[bis.available()];
bis.read(b);
if(b!=null){
String [] strs= new String(b).split(";");
if (strs==null) {
return null;
}
for (String string : strs) {
String[] str = string.split(",");
Course course = new Course();
course.setAssessment(str[5].trim());
course.setClassNum(str[0].trim());
course.setCredit(str[1].trim());
course.setEndClassDate(str[3].trim());
course.setStartClassDate(str[2].trim());
course.setTeacher(str[4].trim());
list.add(course);
}
}
bis.close();//关闭流(关闭bis就可以了)
return list;
}
}
package main;
import java.util.List;
public class Student {
private String name;
private String number;
private ListCourse courses;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public ListCourse getCourses() {
return courses;
}
public void setCourses(ListCourse courses) {
this.courses = courses;
}

}
001,1,7,8,Joyce,assignment;
002,1,8,9,Joyce,assignment;
003,1,12,15,Joyce,assignment;
004,1,18,19,Joyce,assignment;
005,1,7,8,LI,assignment;
006,1,8,9,LI,assignment;
007,1,12,15,LI,assignment;
008,1,18,19,LI,assignment;
【java手把手教你写代码 java代码怎么写】关于java手把手教你写代码和java代码怎么写的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读