forked from TusharKukra/Hacktoberfest2021-EXCLUDED
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNoOfLines.java
31 lines (31 loc) · 1015 Bytes
/
NoOfLines.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.io.*;
import java.util.*;
public class NoOfLines
{
public static void main(String args[])
{
try
{
Scanner in = new Scanner(System.in);
System.out.println("Enter the source code location whose number of lines you want to calculate");
String location = in.nextLine();
FileInputStream fi = new FileInputStream(location);
Scanner file = new Scanner(fi);
int ans = 0;
while (file.hasNextLine())
{
String temp = file.nextLine();
ans++;
}
System.out.println("The number of lines in the file is " + ans);
fi.close();
in.close();
file.close();
}
catch(Exception e)
{
System.out.println("File is not found or File is not compatible for calculation of number of lines");
System.out.print(e.getMessage());
}
}
}