我必须读一个如下的txt文件: ” 1 1 B 2 20 ” 与制表符分隔符。 我的老师在我的代码中提供了帮助,但仍然出现“找不到符号”错误。 你能帮我吗?
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.awt.List;
public class CityLife{
public static void main(String[] args){
List<City> list = new ArrayList<City>();
try (BufferedReader br = new BufferedReader(FileReader("example.txt"))) {
String sC = null;
while((sC = br.readLine()) != null) {
String [] separatedInputs = sC.split("\t");
String cityName = separatedInputs[0];
int population = Integer.parseInt(separatedInputs[1]);
double area = Double.parseDouble(separatedInputs[2]);
City people = new City(cityName,population,area);
list.add(City);
}
} catch (IOException e) {
System.err.println("Error occured at File reading!");
}
}
}