Java--io class, character stream reading data

Source: Internet
Author: User

inputstreamreader reading Data
InputStreamReader Read Data method
     ?              public int read (); Reads a single character.      ?             public int Read (char[] cbuf); Reads a character into an array.      ?            public int Read (char[] cbuf,int off, int len); Reads a character into a part of the array.
public static void Main (string[] args) throws IOException {
FileInputStream fis = new FileInputStream ("1.txt"); InputStreamReader ISR = new InputStreamReader (FIS);//Does not specify the encoding format, the default system code (UTF-8);
//Method One:/* int ch;//while ((ch = (char) isr.read ())! =-1) { //Here cannot be forcibly converted to char here, converted to Char will never equal to-1While ((ch = isr.read ())! =-1) {System.out.print ((char) ch); } */
//Method two:/* char[] Charray = new CHAR[10];int leng = Isr.read (Charray);System.out.println (Charray); * *
//Method Three: / * char[] charray2 = new CHAR[10]; int leng2 = Isr.read (Charray2, 0,charray2.length); System.out.println (charray2); * *
char[] charray2 = new CHAR[10]; int Leng; While ((Leng = Isr.read (charray2,0,charray2.length))! =-1) { //system.out.print (charray2); //cannot directly output the array, because the last read into the array length of the data, will cause the output of the last read into the array String charray2str = new string (Charray2,0,leng); System.out.print (CHARRAY2STR);                 }
fis.close (); isr.close ();         } }































Java--io class, character stream reading data

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.