-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileReadWrite.java
More file actions
34 lines (29 loc) · 1.03 KB
/
Copy pathFileReadWrite.java
File metadata and controls
34 lines (29 loc) · 1.03 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
import java.io.*;
//import java.util.Scanner;
import java.util.StringTokenizer;
public class FileReadWrite {
public static void main(String[] args) {
try {
double total=0;
int product=0;
FileReader fr = new FileReader("in.txt");
BufferedReader br = new BufferedReader(fr);
String strLine;
FileWriter wr = new FileWriter("out.txt");
PrintWriter pw = new PrintWriter(wr);
while ((strLine = br.readLine()) != null) {
StringTokenizer data = new StringTokenizer(strLine,";");
data.nextToken();
double price = Double.parseDouble(data.nextToken());
total=total+price;
product++;
}
pw.println("Product :"+product+"Total :"+total);
br.close();
pw.close();
}
catch(Exception e) {
System.err.println("Error : "+e.getMessage());
}
}
}