• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Filewriter and Unwanted Blank Lines

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my first question on coderanch. I have done some googling ( and the results did include coderanch)
but the problem there is that the questions and answers I found are sufficiently different from my own to make them effectively useless to me.
So here is where I am :

I have an existing text file and I want to add/append a new record to it.
The code below does indeed do that but for some reason it also adds a blank line, which I absolutely do NOT want.
How do I prevent the blank line being added, please ?
Thank you in advance.

 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

First, welcome to the ranch.

As for your newlines, you have two. First, the string printed has a newline. And second, the println() method adds a newline. Is that the blank line that you are referring to?

Henry
 
Frederick Douglass
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

As for your newlines, you have two. First, the string printed has a newline. And second, the println() method adds a newline



I must admit confusion here. Yes, there are two references to newline and the println adds a newline.
But, if I understand you correctly, you are suggesting that the println is adding the blank line.
In which case how is the ( non-blank ) newline being added ?

And thank you for your rapid reply.
 
Saloon Keeper
Posts: 9556
79
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two new lines in a row will create a blank line, whether the NL comes directly from the String ("\n") or from println();
 
Sheriff
Posts: 3914
542
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Frederick Douglass wrote:... you are suggesting that the println is adding the blank line.
In which case how is the ( non-blank ) newline being added ?


Maybe you don't realize the differnece between print() and println(). With print() your string will be output to the file, but with println(), in addition to outputing your string to the file, a new-line sequence will also output to the file (\n for Linux/Mac, \r\n for Windows).
 
Frederick Douglass
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Removing the "ln" from "println" did work, thanks.
I did know the significance of "ln" in the context of "System.out.println".
But here I assumed the "\n" was about positioning of the line throw rather than the line throw itself.

Another problem solved, thanks very much.
 
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic