-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtm_filehandling.java
More file actions
43 lines (40 loc) · 1.31 KB
/
Copy pathAtm_filehandling.java
File metadata and controls
43 lines (40 loc) · 1.31 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
33
34
35
36
37
38
39
40
41
42
43
import java.util.Scanner;
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
public class Atm_filehandling{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter Id:");
String id=sc.nextLine();
id+=".txt";
try {
File myFile=new File(id);
if(myFile.createNewFile()){
System.out.println("File Created");
}
} catch (Exception e) {
System.out.println("Error in File Creation");
}
try {
FileWriter writer=new FileWriter(id);
System.out.println("Enter Your Pin:");
String pin=sc.nextLine();
System.out.println("Enter Balance:");
String balance=sc.nextLine();
writer.write(pin+","+balance);
writer.close();
} catch (Exception e) {
System.out.println("Error In File writing");
}
try {
Scanner sc1=new Scanner(new File(id));
while(sc1.hasNextLine()){
String data=sc1.nextLine();
System.out.println(data);
}
} catch (Exception e) {
System.out.println("Error In File Reading");
}
}
}