Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

writing to a text file  RSS feed

 
indrajit bose
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using RandomAccessFile class to write to a simple text file using writeChars() and writeInt() methods.when i open the text file to see the contents only the charecters are visible but integers are showing some ascii values.what could be the probable solution?feel free to mail me at indrajit_bose@hotmail.com
thanks in advance

 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Were you expecting writeInt() on RandomAccessFile to write a text string containing the integer value? If so, that's not what it does. The writeInt() method on a RandomAccessFile writes the integer in its native binary form (always 4 bytes, not always readable text), not as text characters.
If you want your text file to be human-readable, you need to convert your integer value to a String. For example, Integer.toString(). If you do not need your text file to be human-readable, then binary form is more efficient.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!