-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain3.java
More file actions
43 lines (37 loc) · 1019 Bytes
/
Copy pathMain3.java
File metadata and controls
43 lines (37 loc) · 1019 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package dIOstream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class Main3 {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
writeFile();
}
private static void readFile() throws IOException{
try (InputStream input = new FileInputStream("src/readme.txt")){
int n;
while ((n = input.read()) != -1){
System.out.println(n);
}
}
}
private static void readFileBuffer() throws IOException{
try (InputStream input = new FileInputStream("src/readme.txt")){
byte[] buffer = new byte[100];
int n;
while ((n = input.read()) != -1){
System.out.println(n);
}
}
}
private static void writeFile() throws IOException{
try (OutputStream output = new FileOutputStream("output.txt")){
byte[] b1 = "hello".getBytes("UTF-8");
output.write(b1);
byte[] b2 = "你好".getBytes("UTF-8");
output.write(b2);
}
}
}