7 Replies Latest reply on Jan 18, 2007 7:48 AM by 807599

    Reading a unicode file !!!

      I'm able to display the unicode text in my jsp page. That is through the character reading, but there is a limit in this reading when it exceeds its limit it shows the error. Could i use something else than character reading. Could anyone help me out in this unicode reading. Here is my code
      File ff = new File(tmp,"unicodeMsg.txt");
                      if(ff.canRead()) {
                          FileInputStream in = new FileInputStream(ff);
                          byte len = (byte) ff.length();
                          byte[] ch = new byte[len];                        
                          String strUnicode = new String(ch,"UTF-8");
                      } else {
      It is displaying the unicode character but when i write more than 50 or even more than that then i'm not able to display it. Could anyone tell me what i've to use to read the unicode character.
      in advance thanks....
        • 1. Re: Reading a unicode file !!!
          Use a BufferedStream or a BufferedReader as you prefer.

          I have no idea what limit you are on about or what any of this has to do with any charset in particular or unicode and I rather think you don't know either.

          So try a buffered in of some sort and then if you are having problems come back and post whatever error message and whatever exact problem you are having.
          • 2. Re: Reading a unicode file !!!
            Here i'm reading as byte reader or otherwise for
            String strUnicode = new String(ch,"UTF-8");
            i don't have anything else to read as someother array. For first argument i think it takes only character. I'm getting this error.......
            can u provide me code for this....
            • 3. Re: Reading a unicode file !!!
              byte len = (byte) ff.length();
              byte[] ch = new byte[len];
              is bad news. You are casting a long into a byte so you're losing 7 bytes worth of valuable information.

              This is a little better.
              int len = (int) ff.length();
              byte[] ch = new byte[len];
              • 4. Re: Reading a unicode file !!!
                i've put ur code it is working for some limit say 50 characters. But when i give more than that it shows the same error. When there is a text file with say 100 characters unicode in it. I want to read those character and display it on jsp page. When the contents of the unicode file more than 100 characters it is giving me the some error.... or sometimes it truncates the other charcters and show the remaining characters...
                • 5. Re: Reading a unicode file !!!


                  • 6. Re: Reading a unicode file !!!
                    can u provide me a code for this..... still i'm getting error..... it's an abstract class, only method i've to implement..
                    • 7. Re: Reading a unicode file !!!
                      public InputStreamReader(InputStream in,
                                               String charsetName)
                                        throws UnsupportedEncodingException
                      //Create an InputStreamReader that uses the named charset.