-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBufferedReaderAndPrintWriter.java
More file actions
28 lines (26 loc) · 988 Bytes
/
BufferedReaderAndPrintWriter.java
File metadata and controls
28 lines (26 loc) · 988 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
import java.io.*;
/**
* @author Divyam (https://github.com/DevYam)
* @created 17/09/2020 - 20:37
* @project java
*/
public class BufferedReaderAndPrintWriter {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\I516379\\IdeaProjects\\java\\src\\randomtext.txt"));
String Line = br.readLine();
int sum = 0;
char arr [] = Line.toCharArray();
for (int i = 0; i < arr.length; i++) {
try{
int n = Integer.parseInt(arr[i]+"");
sum+=n;
}catch (Exception e){
}
}
System.out.println(sum);
// System.out.println(sum);
//TODO PrintWriter is not working, will have to look into it
PrintWriter printWriter = new PrintWriter(new FileOutputStream(new File("C:\\Users\\I516379\\IdeaProjects\\java\\src\\randomtext.txt"),true));
printWriter.println(sum);
}
}