• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to prevent the garbage characters like ¿ while creating a file in java

 
vdammala vkumar
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

when i try to view the file generated by java in unix box it shows some garbage characters  like this , i have tried encoding type UTF8 but it doesn't work out.
Please let me know if anybody has faced this issue before.

Thanks,
Vijay
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java writes exactly the characters you tell it to. Without more details, it's impossible to say exactly what you're doing wrong, but here are some possibilities:

  • Trying to write/read binary data as text.
  • Not writing what you think you're writing.
  • Using the wrong encoding to write the text in your Java code.
  • Using the wrong encoding to read the text, or using a tool to read it that doesn't understand that encoding.
  • Using a font in whatever tool you're reading using to read the text that doesn't support the characters written.


  • Also: ItDoesntWorkIsUseless, so please TellTheDetails. Without seeing exactly what you wrote, exactly how you wrote it, and exactly how you're reading it, we can only guess at what the problem might be.
     
    Jeff Verdegan
    Bartender
    Posts: 6109
    6
    Android IntelliJ IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    And welcome to the Ranch!
     
    vdammala vkumar
    Ranch Hand
    Posts: 64
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,

    I know it doesn't do anything extra , when i open the file in unix box these garbage characters appear in the file.
    we can change the encoding type in unix console to see the actual text but i want to make it OS/Editor indenpendant.

    Thanks,
    Vijay
     
    Jeff Verdegan
    Bartender
    Posts: 6109
    6
    Android IntelliJ IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    vdammala vkumar wrote:Hi,

    I know it doesn't do anything extra , when i open the file in unix box these garbage characters appear in the file.


    That doesn't address any of the points I raised.

    we can change the encoding type in unix console to see the actual text but i want to make it OS/Editor indenpendant.


    There's nothing you can do with the file itself to guarantee that every editor on every OS will be able to automagically display it correctly. When reading a file, you have to know the encoding, and you have to tell whatever is reading it to use that encoding, whether that's setting the encoding in your java code before reading it, or selecting it from a menu in a text editor.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!