Java FileInputStream.read()方法範例
FileInputStream
的FileInputStream.read()
方法具有以下語法。
public int read() throws IOException
在下面的程式碼顯示如何使用FileInputStream.read()
方法。
import java.io.IOException;
import java.io.FileInputStream;
public class Main {
public static void main(String[] args) throws IOException {
int i = 0; // By: W w w .YI I bA I.c OM
// create new file input stream
FileInputStream fis = new FileInputStream("C://test.txt");
// read till the end of the file
while ((i = fis.read()) != -1) {
// converts integer to character
char c = (char) i;
System.out.print(c);
}
}
}