counting the number of lines in a text file (java)
问题 Below is how i count the number of lines in a text file. Just wondering is there any other methods of doing this? while(inputFile.hasNext()) { a++; inputFile.nextLine(); } inputFile.close(); I'm trying to input data into an array, i don't want to read the text file twice. any help/suggestions is appreciated. thanks 回答1: If you just want to add the data to an array, then I append the new values to an array. If the amount of data you are reading isn't large and you don't need to do it often