-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileReadernWriter.java
More file actions
37 lines (36 loc) · 927 Bytes
/
Copy pathFileReadernWriter.java
File metadata and controls
37 lines (36 loc) · 927 Bytes
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
37
package javalab;
import java.util.*;
import java.io.*;
public class FileReadernWriter
{
public static void main(String[] args)
{
try
{
Scanner sc = new Scanner(System.in);
File obj1 = new File("Register1.txt");
obj1.createNewFile();
System.out.println("Register1.txt created\n");
FileWriter fout = new FileWriter("Register1.txt");
System.out.println("Register1.txt");
System.out.println("Enter your KEAM rank: ");
int n = sc.nextInt();
fout.write(n+ "\n");
fout.close();
System.out.println("Data added!");
FileReader fin = new FileReader("Register1.txt");
BufferedReader br = new BufferedReader(fin);
String line;
System.out.println("\nContent of Register1.txt is:");
while((line = br.readLine()) != null)
{
System.out.println(line);
}
br.close();
}
catch (IOException e)
{
System.out.println("Exception occured: " +e.getMessage());
}
}
}