-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavaFile30
56 lines (50 loc) · 1.69 KB
/
JavaFile30
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
// file homework 25-90 all even tasks
package Workshop;
import java.io.*;
import java.io.IOException;
import java.util.*;
import java.io.FileNotFoundException;
public class Main {
public static void main(String[] args) throws FileNotFoundException
{
BufferedReader br = null;
BufferedReader br1 = null;
try{
br = new BufferedReader(new FileReader("src/Workshop/note.txt"));
File file = new File("src/Workshop/output.txt");
FileWriter fw = new FileWriter(file,true);
BufferedWriter bw = new BufferedWriter(new BufferedWriter(fw));
System.out.println("Reading file: ");
int cnt = 0;
int index = 0;
int min = 49;
int max = 49;
int sum=0;
int[] arr = new int [20];
//Reading
while((cnt=br.read())!= -1){
arr[index] = cnt;
index++;
}
if(index%2!=0) throw new IllegalArgumentException("odd");
System.out.println("Printing an array :");
for (int value : arr) {
System.out.print((char) value + " ");
}
//Writing: ...
for (int j = 0; j < index/2; j++) {
bw.write(arr[j]);
}
bw.close();
System.out.println("Reading from output file: ");
br1 = new BufferedReader(new FileReader("src/Workshop/output.txt"));
while((cnt=br1.read())!= -1){
System.out.print((char)cnt+" ");
}
}
catch(IOException e){
System.out.println("Exception thrown ");
e.printStackTrace();
}
}
}