大体的实现功能,代码写的并不严谨,很多需要判断的地方都没判断,你凑合看看功能是如何实现的就行,至于各种判断验证什么的你自己搞定吧。
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class FileToArray {
public static void main(String[] args) throws IOException {
String path = FileToArray.class.getResource("data.txt").toString()
.substring(6);
File file = new File(path);
BufferedReader in = new BufferedReader(new FileReader(file));
List
String line;
int flg = 1;
while ((line = in.readLine()) != null) {
String[] data = line.split(" ");
String name = data[0];
long id = Long.parseLong(data[1]);
String[] result = new String[data.length - 2];
for (int i=2; i
}
Student0 sdt = new Student0(name, id, result);
students.add(sdt);
}
in.close();
in = null;
file = null;
for (Student0 std : students) {
System.out.println(std.getName() + " " + std.getId());
for (String res : std.getResult()) {
System.out.println(res);
}
System.out.println("=================");
}
}
}
class Student0 {
private String name;
private long id;
private String[] result;
public Student0(String name, long id, String[] result) {
this.name = name;
this.id = id;
this.result = result;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String[] getResult() {
return result;
}
public void setResult(String[] result) {
this.result = result;
}
}
不是很明白你的要求
for(int i=0;i <200;i++){特别是对于 这行,不明白
这个循环
while ((line = in.readLine()) != null){
System.out.println(line);
}
已经把文件从头读到尾了,你的循环是用来做什么的?
读取的数据就在System.out.println(line);
那里处理,不明白你的String name,Long id,double result[]怎么对应,所以不敢写,你对应起来再说吧(不明白id对应哪个,name对应哪个,result是不是对应分数?)