Use of the Java.lang.io package

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.