【发布时间】:2016-05-19 17:41:24
【问题描述】:
我希望将第 5 行中打印的值插入到整数数组中。
该文件同时包含整数值和字符串值。
****我还在学习中****
对不起,我稍微改变了问题。
谢谢
File f = new File("SampleInput.txt");
try{
ArrayList<String> lines = get_arraylist_from_file(f);
for(int x =23; x < lines.size(); x++){
System.out.println(lines.get(x));
**enter code here**
}
}
catch(Exception e){
System.out.println("File not found!!!!");
}
}
public static ArrayList<String> get_arraylist_from_file(File f)
throws FileNotFoundException {
Scanner s;
ArrayList<String> list = new ArrayList<String>();
s = new Scanner(f);
while (s.hasNext()) {
list.add(s.next());
}
s.close();
return list;
}
【问题讨论】:
-
为什么不使用列表而不是数组?
标签: java arrays list file-handling