-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab7Q1.java
36 lines (31 loc) · 1.05 KB
/
Lab7Q1.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
32
33
34
35
36
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Lab7Q1 {
public static void main(String[] args) {
String infileName = "Lab7Data.txt";
String outfileName = "lab7output.txt";
Scanner reader = null;
PrintWriter writer = null;
try {
reader = new Scanner(new File(infileName));
writer = new PrintWriter(outfileName);
int lineNo = 1;
while (reader.hasNext()) {
String oneLine = reader.nextLine();
System.out.println(lineNo + "" + oneLine);
writer.println(lineNo + "" + oneLine);
lineNo++;
}
} catch (FileNotFoundException err) {
System.out.println(err);
} finally {
if (reader != null)
reader.close();
if (writer != null)
writer.close();
}
System.out.println("End of main method");
}
}