我想读取一个文本文件,其中包含String和与该字符串相关的几个整数.
这是我必须编写程序的类:
public List<Integer> Data(String name) throws IOException {
return null;
}
Run Code Online (Sandbox Code Playgroud)
我必须读取.txt文件并在其中找到该文件中的名称及其数据.并保存在一个ArrayList.
我的问题是我怎么保存它的ArrayList<Integer>时候我已经String在S List.
这就是我想我会做的事情:
Scanner s = new Scanner(new File(filename));
ArrayList<Integer> data = new ArrayList<Integer>();
while (s.hasNextLine()) {
data.add(s.nextInt());
}
s.close();
Run Code Online (Sandbox Code Playgroud)