1 Packagefile operation;2 3 ImportJava.io.File;4 ImportJava.io.FileInputStream;5 Importjava.io.IOException;6 ImportJava.io.InputStream;7 8 Public classTestinputstream {9 Public Static voidMain (string[] args)throwsIOException {TenFile file=NewFile ("D:" +file.separator+ "Test.txt"); One A /*read file contents at once - if (file.exists ()) { - inputstream inputstream=new fileinputstream (file); the byte[] bytes=new byte[1024]; - int Length=inputstream.read (bytes); - inputstream.close (); - System.out.println ("" "+new String (bytes,0,length) +" ""); + } - */ + A if(File.exists ()) {//Single Read atInputStream inputstream=Newfileinputstream (file); - byte[] bytes=New byte[1024]; - intFoot=0; - byteTmp=0; - while((Tmp= (byte) Inputstream.read ())!=-1) -bytes[foot++]=tmp; in inputstream.close (); -System.out.println ("" "+NewString (bytes,0,foot) + "" "); to } + } -}View Code
Byte input stream of "Java" IO stream: Java.io.InputStream class and Subclass Java.io.FileInputStream