forked from Drun1baby/JavaSecurityLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileInputRead02.java
More file actions
32 lines (29 loc) · 1003 Bytes
/
Copy pathFileInputRead02.java
File metadata and controls
32 lines (29 loc) · 1003 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
package src.IOStream;
import java.io.FileInputStream;
import java.io.IOException;
// read(byte[] d) 方法,允许在方法中添加一个字节数组
public class FileInputRead02 {
public static void main(String[] args) {
readFile();
}
public static void readFile(){
String filePath = "Serialable/src/IOStream/CreateForFile/new1.txt";
FileInputStream fileInputStream = null;
byte[] cache = new byte[8]; // 设置缓冲区,缓冲区大小为 8 字节
int readLen = 0;
try {
fileInputStream = new FileInputStream(filePath);
while((readLen = fileInputStream.read(cache)) != -1){
System.out.println(new String(cache, 0, readLen));
}
} catch (IOException e){
e.printStackTrace();
} finally {
try {
fileInputStream.close();
} catch (IOException e){
e.printStackTrace();
}
}
}
}