?? fileinputstreamdemo.java~2~
字號:
package fileinputstream;
/**
Total Available Bytes: 25
First 0 bytes of the file one read() at a time
Still Available: 25
Reading the next 0 with one read(b[])
Still Available: 25
Skipping half of remaining bytes with skip()
Still Available: 13
Reading 0 into the end of array
Still Available: 13
*/
// Demonstrate FileInputStream.
import java.io.*;
class FileInputStreamDemo {
public static void main(String args[]) throws Exception {
int size;
InputStream f =
new FileInputStream("FileInputStreamDemo.java");
System.out.println("Total Available Bytes: " +
(size = f.available()));
int n = size / 40;
System.out.println("First " + n +
" bytes of the file one read() at a time");
for (int i = 0; i < n; i++) {
System.out.print( (char) f.read());
}
System.out.println("\nStill Available: " + f.available());
System.out.println("Reading the next " + n +
" with one read(b[])");
byte b[] = new byte[n];
if (f.read(b) != n) {
System.err.println("couldn't read " + n + " bytes.");
}
System.out.println(new String(b, 0, n));
System.out.println("\nStill Available: " + (size = f.available()));
System.out.println("Skipping half of remaining bytes with skip()");
f.skip(size / 2);
System.out.println("Still Available: " + f.available());
System.out.println("Reading " + n / 2 + " into the end of array");
if (f.read(b, n / 2, n / 2) != n / 2) {
System.err.println("couldn't read " + n / 2 + " bytes.");
}
System.out.println(new String(b, 0, b.length));
System.out.println("\nStill Available: " + f.available());
f.close();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -