Flush Flush () method for file progressive write BufferedWriter

Source: Internet
Author: User

FileOutputStream inheritance OutputStream does not provide overrides for the Flush method
So no matter how much content write will pass the binary stream directly to the underlying operating system flush no effect
The input and output stream functions of the buffered series can be seen from the word buffered that they are using buffers
The application each IO to communicate with the device, inefficient, so the buffer to improve efficiency, when writing to the device, write to the buffer, wait until the buffer has enough data, the overall write to the device
The line of the Landlord flush () can not write but the close () to take up, flush will flush the buffer, and the Close method will call the Flush method and then execute the Close method, similar.

 PackageSrc.readfile;ImportJava.io.BufferedWriter;ImportJava.io.File;Importjava.io.FileNotFoundException;ImportJava.io.FileWriter;Importjava.io.IOException;ImportJava.util.Scanner; Public classReadFile { Public Static voidMain (string[] args) {Try {            //maximum number of cards used            intMaxcardno = 497895; //int maxcardno = 10; //The maximum number of bars used by the card number            intCountcardno = 119039; //int countcardno = 3;Scanner in =NewScanner (NewFile ("D:" +file.separator+ "Cardno.txt")); //Initialize the number of read-in file data            Long[] Inputarr =New Long[Countcardno]; inti = 0; System.out.println ("Read in File contents:");  while(In.hasnextline ()) {String str=In.nextline (); STR= Str.substring (5); Long intTemp=Long.parselong (Str.trim ()); //Splitt (str);//System.out.println (intTemp);inputarr[i++]=intTemp; } string[] Outputarr=Newstring[60000]; String cardnotemp= ""; //unused card number circular recording            intAbak = 1; //unused card-numbered group subscript record            intOuti = 0; //output file GenerationString filePath1 = "D:" +file.separator+ "Output.txt"; Try{FileWriter FW=NewFileWriter (FILEPATH1); BufferedWriter BW=NewBufferedWriter (FW); System.out.println ("Unused card numbers are as follows:");  for(intinputi=0;inputi<countcardno;inputi++) {                     for(intA=abak; a<=maxcardno; a++) {                           if(a==Inputarr[inputi]) {Abak=++A;  Break; } Else{cardnotemp= "04003" + Codeaddzero (string.valueof (a), 9); Outputarr[outi++] =cardnotemp;                            Bw.write (cardnotemp);                             Bw.newline (); System.out.println ("No Use for Cardno:" +cardnotemp);                }}} Bw.flush ();                Bw.close ();            Fw.close (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); }         } Catch(FileNotFoundException e) {e.printstacktrace (); }     }     /*** Card number automatic pre-fill 0 operation *@paramCode *@paramLen *@return     */     Public StaticString Codeaddzero (String code,intLen) {String Strcode=Code;  while(Strcode.length () <Len) {Strcode= "0" +Strcode; }        returnStrcode; }}
ReadFile

Flush Flush () method for file progressive write BufferedWriter

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.