【发布时间】:2015-06-12 23:53:08
【问题描述】:
我想读取一个文件,假设它有 3 行:
2
Berlin 0 2 2 10000 300
Nilreb 0 2 2 10000 300
第一个整数显示我有多少个名字(行)。
第 2 行和第 3 行显示有关两个邮局的信息。
我想他们读取每一行并保存数据。
我必须创建以它们为名称的邮局:Berlin 和 Nilreb。
谁能帮助我?
到目前为止,我已经这样做了:
public static void read_files() throws IOException{
Scanner in = new Scanner(new File("offices")); //open and read the file
int num_of_lines = in.nextInt();
while(in.hasNext()){
String offices = in.nextLine();
}
【问题讨论】:
-
Scanner也有nextInt和其他类似的对你有用的功能。 -
你要创建一个 PostOfficer 类来存储数据吗?
-
是的,我正在创建 PostOffice 类