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 ...) )