我在本实验中的任务是接受多个输入文件,其格式与所有文件类似,只是某些文件有注释,我想跳过注释行。例如:Java - 扫描仪评论跳过
输入文件:
Input file 1
#comment: next 5 lines are are for to be placed in an array
blah 1
blah 2
blah 3
blah 4
blah 5
#comment: next 2 line are to be placed in a different array
blah 1
blah 2
#end of input file 1
我试图做什么我用了2 while循环(如果需要的话我可以张贴我的代码)。我做了以下
while(s.hasNext()) {
while(!(s.nextLine().startWith("#")) {
//for loop used to put in array
array[i] = s.nextLine();
}
}
我觉得这应该工作,但事实并非如此。我在做什么不正确。请帮忙。先谢谢你。
你忘了s.hasNext() –
@ThomasMueller - 我没有,我只保留在目标代码的本质。 – MByD