The next generation Mordern iSeries Developer
Steve
Steve Luke wrote:The \n is not a universal line separator. Use System.getProperty("line.separator"); instead.
The next generation Mordern iSeries Developer
Campbell Ritchie wrote:There is a method in BufferedWriter which appends a new line to the file, using the system‑specific line terminator. It is obvious when you read the method names.
Steve
Campbell Ritchie wrote:It is better to use a StringBuilder than + on Strings inside a loop. You can append the line end String, which you get as you told OP the other day.
Campbell Ritchie wrote:
There is a method in BufferedWriter which appends a new line to the file, using the system‑specific line terminator. It is obvious when you read the method names.
True, but the OP is building the entire output in memory first, then sending through the writer at once. I guess a better option would be to read a line, check if it should be saved, write the line. It would be more memory efficient.
The next generation Mordern iSeries Developer
Steve
Steve Luke wrote:My strategy would probably be to read from one file, write to a temp file. Then when done, delete the original and move the temp file to the same path (and name) as the original.
The next generation Mordern iSeries Developer
Campbell Ritchie wrote:If you suffer such permission problems, and cannot create a file, you will suffer a FileNotFoundException, which you must handle (it is “checked”). You can put your file‑copying method call inside a loop, and handle the Exception by trying a different location for your file.
On the other hand, you said you were going to write a file; that suggests to me you have read‑and‑write permission in that folder already.
The next generation Mordern iSeries Developer
Campbell Ritchie wrote:If you suffer such permission problems, and cannot create a file, you will suffer a FileNotFoundException
The next generation Mordern iSeries Developer
Don't get me started about those stupid light bulbs. |