我正在创建一个简单的程序来从文本文件中读取数据.该文件存储有关某人的信息,每行包含姓名,年龄和编号:
例如:每行的文件格式
Francis Bacon 50 2
如果它只是文本,我可以在文件中读取没有问题,但我对如何区分文本和数字感到困惑.这是我的代码:
import java.io.*;
public class Test{
private People people[] = new People[5];
public Test(){
BufferedReader input;
input = new BufferedReader(new FileReader("People.txt"));// file to be readfrom
String fileLine;
int i = 0;
while (test != null){
fileLine = input.readLine();
// Confused as to how to parse this line into seperate parts and store in object:
// eg:
people[i].addName(fileLine - part 1);
people[i].addBookNo(fileLine - part 2);
people[i].addRating(fileLine - part 3)
i++
}
}
}