这是我的代码的第一行扫描仪仅读取文本文件
public static void main(String[] args) {
File source = //
Scanner s = null;
int lineNumber =0;
ArrayList<ArrayList<Integer>> tagsArray = new ArrayList<>();
try {
s= new Scanner(source);
while (s.hasNext()) {
String[] cols = s.nextLine().split(" ");
for (int i = 0; i < cols.length; i++) {
if (cols[i].equals("1"))
tagsArray.get(i).add(lineNumber);
}
lineNumber++;
}
} catch (Exception e) {
// TODO: handle exception
}
}
当我删除它读取整个文本文件,但是当我使用它,它只读了第一行 为什么声明?
我会说使用BufferedReader会比使用扫描仪读取文件更好。看看http://www.mkyong.com/java/how-to-read-file-from-java-bufferedreader-example/ – user2280897 2013-04-23 10:30:28