2016-07-24
InputStream
1,fileinputstream
Because a byte stream reads one byte at a time, and one is not completely descriptive of the Chinese,
So there will be normal English, Chinese garbled situation.
Packagecom.java1995;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;Importjava.io.IOException; Public classTestfileinputstream { Public Static voidMain (string[] args) {FileInputStream fis=NULL; intI=0; Try{FIS=NewFileInputStream ("C:\\users\\administrator\\desktop\\hello.txt"); } Catch(FileNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); } Try{i=Fis.read (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } //when the file reaches the end when I==-1 while(I!=-1) {System.out.print (Char) (i); Try{i=Fis.read (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } }}
Packagecom.java1995;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;Importjava.io.IOException; Public classTestfileinputstream { Public Static voidMain (string[] args) {FileInputStream fis=NULL; intI=0; Try{FIS=NewFileInputStream ("D:\\workspace\\java_io\\hello.txt"); } Catch(FileNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); } Try{i=Fis.read (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } //when the file reaches the end when I==-1 while(I!=-1) {System.out.print (Char) (i); Try{i=Fis.read (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } }}
Resources
[1] Java Easy Start Classic tutorial "full version"
Javase Advanced Section No. 07 file input stream FileInputStream