Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing String representation to file

 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using BufferedWriter class that wraps FileWriter class to store data in a file. However I am facing some issues regarding what is written.

I have this method which is passed an integer. But while writing it gets correctly written only when I am appending to a empty string using + operator.

Using an overloaded method which takes an int results in character 'a' with a diacritical mark ending up in the file.

Following is what I have so far. What is a good way of doing this?



 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BufferedWriter.write is for writing a character not an integer. Use When you call it with an int it looks up the character represented by that int value.
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. Its helpful to know the cause of why the special characters are written.

Is the using of static method valueOf() the preferred way? I suppose using Integer wrapper class and running toString on it would be an overkill.
 
E Armitage
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahsan Bagwan wrote:Thank you. Its helpful to know the cause of why the special characters are written.

Is the using of static method valueOf() the preferred way? I suppose using Integer wrapper class and running toString on it would be an overkill.


The String.valueOf method calls the Integer.toString method. You should use a method that you think best communicates what your code is doing.
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!