Forgetting to add close() when writing an array to file with Java's PrintWriter, the last part of the array will be left out. Why is that? -


I noticed that I did not know about writing an array to use the print-vaator class of Java. When I forgot to add the end () to the end, the last element of the array was not printed in the file. Why is it like this?

Snippets from code:

  ... PrintWriter f; Try {f = new PrintWriter (new FileWriter ("out.txt")); For (Int i = 0; I & lt; Array.Label; I ++) {// array contains 5000+ birthdays f.println (array [i]); } F.close (); // The last element of the array will not be printed if this line has been removed} catch (IOException e) {System.out.println ("exception:" + E); }  

  close ()  
< P> The method will close the stream of data, and any data will remain in the output pipes. So if you do not call the off () method, then the flush is not happening, and the resource is still closed after the gc is run, this unpublished streams You can get it, and it will be stopped suddenly, where you do not have a mechanism to flush the data into output (no output!)


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -