Skip to Content
author's profile photo Former Member
Former Member

Language problem when reading from a file



I have a text file which contains data in Hebrew.

I am using these lines in order to read from the file:

File inputFile = new File("C:

BufferedReader input = new BufferedReader (new FileReader (inputFile));

while ((line = input.readLine()) != null)


The problem is that when I print what I read I receive "Gibrish" letters which is impossible to read, it looks like the collection of the data doesn't keep the language. Is there any way to solve this? perhaps converting the String in some way?


Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 26, 2005 at 11:00 AM

    Hi Roy,

    this is a typical encoding issue. Here are some hints:

    1. Try to read the bytes of the text instead of chars.

    In other words use an InputStream instead of a Reader.

    The result should be a byte array.

    2. Be carefully when convert bytes to chars or String

    Don't do just

    String s = new String(bytes);

    Do something like

    String s = new String(bytes, "UTF-8");

    Hope that helps a bit


    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Roy,

      as I stated in the other thread (the one with the URLConnection) You could use an InputStreamReader to bridge from InputStream to a Reader:

      InputStream is = new FileInputStream("anyfile");
      InputStreamReader isr = new InputStreamReader(is, "UTF-8");
      BufferedReader br = new BufferedReader(isr);

      the impotant thing is to care for the correct encoding ("UTF-8") in my example.

      Best Regards


Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.