-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentFile.java
More file actions
32 lines (32 loc) · 1.15 KB
/
StudentFile.java
File metadata and controls
32 lines (32 loc) · 1.15 KB
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
import java.io.*;
import java.util.Scanner;
class StudentFile {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
try { // Write into file
FileWriter fw = new FileWriter("student.txt");
System.out.print("Enter Roll No : ");
int roll = sc.nextInt();
sc.nextLine();
System.out.print("Enter Name : ");
String name = sc.nextLine();
System.out.print("Enter Marks : ");
int marks = sc.nextInt();
fw.write("Roll No : " + roll + "\n");
fw.write("Name : " + name + "\n");
fw.write("Marks : " + marks + "\n");
fw.close();
System.out.println("\nData Written Successfully");
// Read file
FileReader fr = new FileReader("student.txt");
int ch;
System.out.println("\nStudent Information:");
while ((ch = fr.read()) != -1) {
System.out.print((char) ch);
}
fr.close();
} catch (Exception e) {
System.out.println(e);
}
}
}