Tag:java byte stream
/* bytes Stream Inputstreamoutputstream byte throttle buffer bufferedinputstreambufferedoutputstreamsystem.out: corresponding to the standard output device, console system.in: Corresponding standard input device, keyboard InputStreamReader: Character stream converted to byte stream, byte stream and its buffer no ReadLine method, first changed to character stream buffer */package Pack;import Java.io.bufferedinputstream;import Java.io.bufferedoutputstream;import Java.io.bufferedreader;import Java.io.fileinputstream;import Java.io.fileoutputstream;import Java.io.ioexception;import Java.io.InputStream; Import Java.io.inputstreamreader;public class Main {public static void sys (Object obj) {System.out.println (obj ); } public static void Main (string[] args) throws IOException {//method1 (); Method2 (); Method3 (); METHOD4 (); Method5 (); } public static void Method1 () throws IOException {FileOutputStream fos = new FileOutputStream ("E:\\1.txt"); Fos.write ("abc". getBytes ());//write method does not have string parameters, convert to byte array//stream does not need to refresh fos.close (); } public static void Method2 () throws IOException {FILEINPUTSTReam FIS = new FileInputStream ("E:\\1.txt"); /*int ch = 0; while ((Ch=fis.read ())!=-1)//Read one sys ((char) ch) at a time; Fis.close (); */byte[] buf = new Byte[fis.available ()];//fis.available is the number int len = 0; while ((Len=fis.read (BUF))!=-1) sys (new String (Buf,0,len)); Fis.close (); }/* Copy picture, byte stream */public static void Method3 () throws IOException {FileOutputStream fos = new FileOutputStream ( "E:\\2.jpg"); FileInputStream fis = new FileInputStream ("e:\\1.jpg"); int ch = 0; while ((Ch=fis.read ())!=-1) fos.write (CH); Fos.close (); Fis.close (); }/* Copy MP3, through buffer */public static void Method4 () throws IOException {Bufferedoutputstream bufos=new Bufferedou Tputstream (New FileOutputStream ("E:\\2.mp3")); Bufferedinputstream bufis=new Bufferedinputstream (New FileInputStream ("E:\\1.mp3")); int ch = 0; while ((Ch=bufis.read ())!=-1) BUFos.write (CH); Bufis.close (); Bufos.close (); } public static void Method5 () throws IOException {//byte stream and its buffers do not have ReadLine method, first into a character stream buffer inputstream in = Syst em.in; Get keyboard Input Object InputStreamReader ISR = new InputStreamReader (in);//byte stream converted to character stream BufferedReader Bufr = new Bufferedr Eader (ISR); Character stream buffer string line = NULL; while ((Line=bufr.readline ())!=null) {if (Line.equals (' over ')) break; SYS (line); } bufr.close (); }}
Java byte stream