java.io.FileInputStream
No notes
Syntax:
Java
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class Test { try { // using Constructor FileInputStream(File file) // using Constructor FileInputStream(String name) // File file = new File("SampleFile.txt"); // in = new FileInputStream(file); byte[] buffer1 = new byte[] {'*','*'}; byte[] buffer2 = new byte[] {'*','*','*','*','*'}; int count; // 顯示剩餘可讀的 Byte 總數 // int read() // int read(byte[] b) count = in.read(buffer1); // int read(byte[] b, int off, int len) count = in.read(buffer2, 2, 2); // long skip(long n) count = (int)in.skip(2); // skip 通常會傳回 n, 即使超過了 EOF, 也不會有 Exception, // 但可會造成 available()傳回負數的值, 而 read method 也會傳回 -1 e.printStackTrace(); } finally { try { if (in != null) in.close(); e.printStackTrace(); } } } }