I have .csv file and its limit is 500, I used readLine() its take time to check Number of record is 500 or exceeds limit.
Asked
Active
Viewed 490 times
-2
-
I do not completely understand. You want to check if a csv file has more than 500 records (lines)? – JDC Dec 19 '16 at 10:41
-
yes more than 500 not acceptable for process, – Afnan alam Dec 19 '16 at 10:43
-
i just upload .csv file its have 500 record and limit of record is 500 so how to check if record is more than 500 without readLine() bcz its take to much time – Afnan alam Dec 19 '16 at 10:49
-
it takes time to read 500 lines of a file ?? Anyway, you have not the choice, you have to read the content of the file. With a buffer, it is rather efficient : http://stackoverflow.com/questions/453018/number-of-lines-in-a-file-in-java – davidxxx Dec 19 '16 at 10:49
1 Answers
1
there is no chance to access the 500th line directly you need to loop all lines before
public static void main(String args[]) throws IOException {
String FILENAME="path";
BufferedReader bufferedReader = new BufferedReader(new FileReader(FILENAME));
String input;
int count = 0;
while((input = bufferedReader.readLine()) != null)
{
count++;
}
System.out.println("Count : "+count-1); // if you have header
}

Khalil M
- 1,788
- 2
- 22
- 36