1String Source = "ABCDEF123456";2 intMID = Source.length ()/2;3 4Bytearrayinputstream bytesis =NewBytearrayinputstream (Source.getbytes ());5 6 //1. Sequential Read Stream7 intb = 0;8 while(-1! = (b =Bytesis.read ())) {9System.out.print (integer.tohexstring (b) + "");Ten } One System.out.println (); A - //2. Call read after reading always returns-1 -b =Bytesis.read (); the System.out.println (b); - - //the convection is reset - intindex = 0; + Bytesis.reset (); - while(-1! = (b =Bytesis.read ())) { + if(index++ = = Mid &&bytesis.marksupported ()) { A Bytesis.reset (); at } -System.out.print (integer.tohexstring (b) + ""); - } - System.out.println (); - - //Tag Stream inindex = 0; - Bytesis.reset (); to while(-1! = (b =Bytesis.read ())) { + if(index++ = = Mid &&bytesis.marksupported ()) { - //Bytesis.reset (); theBytesis.mark (0); * } $System.out.print (integer.tohexstring (b) + "");Panax Notoginseng } - System.out.println (); the Bytesis.reset (); + while(-1! = (b =Bytesis.read ())) { ASystem.out.print (integer.tohexstring (b) + ""); the } + System.out.println (); - Bytesis.reset (); $ while(-1! = (b =Bytesis.read ())) { $System.out.print (integer.tohexstring (b) + ""); - } - System.out.println (); the - //1. Reading files using FileInputStream can only beWuyiFile File =NewFile ("E:/test.txt"); the System.out.println (File.length ()); -FileInputStream Fileis =Newfileinputstream (file); Wu while(-1! = (b =Fileis.read ())) { -System.out.print ("0x" + integer.tohexstring (b) + "")); About } $ System.out.println (); - - //you can use the Seek method to read files randomly, but for randomaccessfile, it is not a stream class, -String mode = "R"; ARandomaccessfile Randomfile =Newrandomaccessfile (file, mode); + while(-1! = (b =Randomfile.read ())) { theSystem.out.print ("0x" + integer.tohexstring (b) + "")); - } $ System.out.println (); the System.out.println (Randomfile.getfilepointer ()); the System.out.println (Randomfile.length ()); theRandomfile.seek (6); the while(-1! = (b =Randomfile.read ())) { -System.out.print ("0x" + integer.tohexstring (b) + "")); in } the System.out.println (); theRandomfile.seek (0); About while(-1! = (b =Randomfile.read ())) { theSystem.out.print ("0x" + integer.tohexstring (b) + "")); the } the System.out.println (); + - //The Java.lang package has a tool class with text descriptions, but the functionality it provides is also sequential read. the //Java.util.ScannerBayiScanner Scanner =NewScanner (file); the System.out.println (Scanner.next ()); theScanner =Scanner.reset (); - - //Java.io.PushbackInputStream Filter Flow the //This stream provides a unread method that rolls back to the buffer, the Bytesis.reset (); thePushbackinputstream PiS =NewPushbackinputstream (bytesis); thePis.unread (0x30); - System.out.println (integer.tohexstring (Pis.read ())); the System.out.println (integer.tohexstring (Pis.read ())); the the //so far, only the stream classes are basically read and written in the order of the streams. 94Bytearrayoutputstream Bytesoutput =NewBytearrayoutputstream (); the Bytesoutput.write (Source.getbytes ()); the System.out.println (bytesoutput.tostring ()); theBytesoutput.write (0x30);98 System.out.println (bytesoutput.tostring ()); About
Use of the Java.lang.io package