-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileStreamReader.java
More file actions
59 lines (50 loc) · 1.32 KB
/
Copy pathfileStreamReader.java
File metadata and controls
59 lines (50 loc) · 1.32 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// The Character Stream Reader and Writer
import java.io.*;
import java.util.*;
public class fileStreamReader
{
public static void main(String g[]) throws Exception
{
// Read .txt file
FileReader filer = new FileReader("C:\\Users\\Bashyan PC\\Documents\\GitHub\\Java-Starter\\FileReader.txt");
BufferedReader buffer = new BufferedReader(filer);
String s;
while((s = buffer.readLine())!=null)
{
System.out.println(s);
}
filer.close();
// Write Customer details to .txt file
FileWriter filew = new FileWriter("C:\\Users\\Bashyan PC\\Documents\\GitHub\\Java-Starter\\FileWriter.txt");
Scanner ab = new Scanner(System.in);
System.out.println("Enter number of customer details to be stored");
int count = ab.nextInt();
String s1[][] = new String[count][3];
for(int i=0; i<count; i++)
{
System.out.println("Enter customer #"+(i+1)+" ID, Name, Age");
for(int j=0;j<3;j++)
{
s1[i][j] = ab.next();
}
}
for(String[] A : s1)
{
for(String B : A)
{
filew.write(B);
}
}
System.out.println("Customer_ID"+"\t"+"Name"+"\t\t"+"\tAge");
for(int i=0; i<count; i++)
{
for(int j=0;j<3;j++)
{
System.out.print(s1[i][j]+"\t\t\t");
}
System.out.println("");
}
System.out.println("File Written");
filew.close();
}
}