我正在创建一个简单的程序来从文本文件中读取数据。该文件中存储一个人的信息,名称,年龄,每行一个数字:Java:我如何从文件中读取文本和数字
如:每行文件格式
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++
}
}
}
我强烈建议他学习一些编程... – Gabe
很大。我没有使用正则表达式的经验,我该如何将它存储在字符串中? – BodhiByte