We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a935632 commit ab723d3Copy full SHA for ab723d3
FileScannerPrinter
@@ -0,0 +1,27 @@
1
+import java.io.File;
2
+import java.io.FileNotFoundException;
3
+import java.util.Scanner;
4
+
5
+public class FileScannerPrinter {
6
7
+ public static void main(String[] args) throws FileNotFoundException {
8
+ // TODO Auto-generated method stub
9
10
+ //creating File instance to reference text file in Java
11
+ File text = new File("test.txt");
12
13
+ //Creating Scanner instnace to read File in Java
14
+ Scanner scnr = new Scanner(text);
15
16
+ //Reading each line of file using Scanner class
17
+ int lineNumber = 1;
18
19
+ while(scnr.hasNextLine()){
20
+ String lineContent = scnr.nextLine();
21
+ System.out.println(lineNumber + " " + lineContent);
22
+ lineNumber++;
23
+ }
24
25
26
27
+}
0 commit comments