Connection problems in Java when the initial value of a string type variable is null

Source: Internet
Author: User

Today in a very simple Android read the code of the file is a problem encountered. To find out how shaky the Java Foundation is. The first is that the string type variable s is not assigned the initial value of the strings with the automatic connector "+ =", the result is of course an error. Then I'm going to assign s an initial value of NULL, and then connect it as a null string on the connection ... ; The code is as follows:

1 Private voidUpdateFile3 ()throwsIOException {2FileReader FileReader =NewFileReader (3"/mnt/sdcard/mytestdata/test.txt");4         Char[] buf =New Char[128];5String s =NULL;6         intstr;7 8          while(str = filereader.read (BUF))! =-1) {9s + = string.copyvalueof (buf, 0, str). toString ();Ten         } One Tv.settext (s); A}

The contents of my test.txt file are "read successfully, Hey, HI". As a result, the content displayed in the TextView control TV becomes "read succeeded, hehe Hey", the workaround is only to string s = null; change to string s = ""; The specific reasons for the next time to read the Java source code to continue, this is only the first to write down their own problems, because in the internet did not find other people encounter this problem. For the first time, record your problems on the CSDN. In the future will often be here to learn from you, Exchange and share.

Connection problems in Java when the initial value of a string type variable is null

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.