📄 fileinputdemo.java
字号:
import java.io.*;
import java.util.*;
public class FileInputDemo {
public static void main(String args[]) throws Exception {
int size;
InputStream f1 = new FileInputStream(args[0]);
size = f1.available(); // total size
System.out.println("Available : " + size);
// Read the first 1/4 by read()
for (int i = 0; i < size / 4; i++) {
System.out.print( (char) f1.read());
}
System.out.println();
System.out.println("Still available : " +f1.available());
// Read the next 1/8 by read(b[])
byte b[] = new byte[size / 8];
if (f1.read(b) != b.length) {
System.err.println("Something bad happened!");
}
System.out.println("Still available : " +f1.available());
// Skip another 1/4: skip()
f1.skip(size / 4);
System.out.println("Still available : " +f1.available());
f1.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -