-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileInputStreamTest.java
More file actions
71 lines (65 loc) · 2.48 KB
/
Copy pathFileInputStreamTest.java
File metadata and controls
71 lines (65 loc) · 2.48 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
60
61
62
63
64
65
66
67
68
69
70
71
package ThreadTest;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import javax.sound.midi.VoiceStatus;
public class FileInputStreamTest {
public static void main(String[] args) throws IOException {
// FileReadTest();
// FileInputStreamTest();
// FileWrite();
PrintStreamTest();
}
public static void FileInputStreamTest() throws IOException {
FileInputStream fiStream = new FileInputStream("/home/hanshizhe/workspace/JavaTest/src/ThreadTest/FileInputStreamTest.java");
FileOutputStream fileOutputStream = new FileOutputStream("/home/hanshizhe/workspace/JavaTest/src/hanshizhe.txt");
byte[] buf = new byte[1024];
int hasRead = 0;
while ((hasRead = fiStream.read(buf))>0) {
System.out.print(new String(buf,0, hasRead));
fileOutputStream.write(buf,0,hasRead);
}
fiStream.close();
fileOutputStream.close();
}
public static void FileReadTest() {
try {
FileReader fReader= new FileReader("/home/hanshizhe/workspace/JavaTest/src/ThreadTest/FileInputStreamTest.java");
char [] buf = new char[32];
int hasRead = 0;
while ((hasRead = fReader.read(buf)) > 0) {
System.out.print(new String(buf,0, hasRead));
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
public static void FileWrite () {
try {
FileWriter fWriter = new FileWriter("/home/hanshizhe/workspace/JavaTest/src/ThreadTest/tangshi.txt");
fWriter.write("韩仕喆\r\n");
fWriter.write("韩仕喆\r\n");
fWriter.write("韩仕喆\r\n");
fWriter.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
public static void PrintStreamTest() {
try {
FileOutputStream fOutputStream = new FileOutputStream("/home/hanshizhe/workspace/JavaTest/src/ThreadTest/tangshi1.txt");
PrintStream ps = new PrintStream(fOutputStream);
ps.println("大唐终端技术有限公司");
ps.println(new FileInputStreamTest());
ps.close();
} catch (Exception e) {
// TODO: handle exception
}
}
}