• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Print and display problem

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,

I have a problem with writing to text file with .txt extension. Wherever i write to it, it print out a new line as a some sort of square character. This only happen when I open the file with notepad but when I open in wordpad it display in normal way meaning it print a new line instead of the character. Is there any way out of this?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rollin Park, your display name does not comply with our naming policy, so I'll have to ask you to click the My Profile link next to the moose head, go to "View/Update Profile", and change the "Publicly Displayed Name" field into something compliant with the policy.
As for your question, the end-of-line marker varies from platform to platform. Windows uses "/n/r", Unix '/n' and Mac '/r'. Since Java is designed to be cross platform one can obtain proper marker in a couple of different ways:
System.getProperties("line.separator") will return it as a String. java.io.PrintWriter.println() will append the proper separator with each call.
java.io.BufferedWriter.newLine() will write a line separator directly to the file.
Use whatever method fits best with your requirements.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
write file as

"abc.txt"
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by shabbir anjum:
write file as
"abc.txt"



That's what Rollin is doing. The extension of a file has no impact on what content a file has. Taking a .txt file and naming it .mp3 does not turn it into an audio file. The problem here is that windows programs like Notepad expect an end-of-line marker of "\n\r" and he's writing "\n".
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't imagine any good reason for using notepad.
scite, for instance, is a powerful, fast and lean editor, freely available, OpenSource, syntax highlightening, ... and flexible in encoding.

I don't know why Microsoft continues selling it - it must be written by Bill Gates himself...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic