我在本實驗中的任務是接受多個輸入文件,其格式與所有文件類似,只是某些文件有註釋,我想跳過註釋行。例如: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