Byte stream two base class InputStream Read OutputStream write character stream two base classes readerwriter These four abstract classes are derived from the subclass of the parent class as a subclass suffix OutputStream Basic method: Close () flush () write () parameter: byte[] b,int B inputstream Basic method Read () int avaliable () Returns the number of bytes remaining in the file. That is, the size of the file, so that you can define an array to fit the data exactly. But the amount of data is too large to use the buffer of the byte stream: Bufferedoutputstream (OS Stream object) write () method bufferedinputstream (Oi Stream object) Read () method Example application: Import java.io.*;p ublic class Test { public static void main ( String[] args) throws ioexception { fileoutputstream fo = new FileOutputStream ("c:\\users\\zx\\ Desktop\\zx.txt "); fo.write (" ABCDE ". GetBytes ()); //does not need to be refreshed, it can be displayed. fo.close (); fileinputstream fl = new FileInputStream ("c:\\users\\zx\\desktop\\ Zx.txt "); int ch=0; while ((Ch=fl.read ())!=-1) { SOP ( Fl.available ()); SOP ((char) ch); } &NBsp; } public static void sop (Object obj) { System.out.println (obj); }} Picture file copy application Import java.io.*;p ublic class Test { public static void main (string[] args) throws ioexception { FileOutputStream fo=null; FileInputStream fi = null; try { fo = new FileOutputStream ( "D://2.png"); fi = new FileInputStream ("D://1.png"); byte [] b = new byte[1024]; int len = 0; whil E ((Len=fi.read (b))!=-1) { fo.write (b,0,len); } } catch (IOException e) { } finally { fi.close (); fo.close (); } } public static void sop (Object obj) { System.out.println (obj); }}
Byte stream of JAVA io stream