Java fundamentals-Input and output stream-large text file read and write another text-----(this program print part of the bug, the output is not normal, the reason is not clear ...) )

Source: Internet
Author: User

Introduction: Title

ImportJava.io.FileInputStream;ImportJava.io.FileOutputStream;/** * @authorCzchina **/ Public classTeststream { Public Static voidMain (string[] args) {FileInputStream FLs=NULL; FileOutputStream Fos=NULL; Try{FLS=NewFileInputStream ("E:/android/androidstudioprojects/text.txt"); FOS=NewFileOutputStream ("E:/android/androidstudioprojects/store.txt"); //generating a byte array            byte[] buffer=New byte[500]; intnum = 0; intTMP = 0; intTMP1 = 0;  for(inti=0;i<3;i++) {tmp= Fls.read (buffer,0, buffer.length); if(-1 = =tmp) {System.out.print ("Read Complete! \ n ");  Break; }                                //Print BufferString buffertostring =NewString (buffer); Buffertostring=Buffertostring.trim (); System.out.println ("Print buffertostring:\n" +buffertostring+ "\ n"); TMP1=tmp; if(500 = =TMP1) {num++; TMP1= 0; } fos.write (Buffer,0, TMP); }            //number of bytes in the streamnum = num*500+TMP1; System.out.println ("Num:" +num); }        Catch(Exception e) {System.out.println (e.tostring ()); }    }}

Input stream Text:

Output stream Text:

Visible: There is no problem with the input and output of the stream.

The following is the console print:

Such as:

1, Problem: red circle text Print two times, unexplained '

2, num count is correct.

Java fundamentals-Input and output stream-large text file read and write another text-----(this program print part of the bug, the output is not normal, the reason is not clear ...) )

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.