troubleshooting Question

Problem redaing unicode file in java-Help!

Avatar of MadhuRini
MadhuRini asked on
Java
4 Comments1 Solution273 ViewsLast Modified:
I have a problem with reading unicode files using java api. The file is a japanese/hindi text file stored as UTF-8 format. Iam reading it using InputStreamReader with encoding as "UTF-8" and putting it to the databse. The DB is MS-SQL Server and is multilingual enabled. The OS is windows NT(English). The characters from the file are being read as "?" and not valid japanse/corresponding characters. Why is this happening.?...Is there something wrong with my program....
Find below the part of the for reading the file:

public static String readFile ( String fileName )
     {
         

          BufferedReader br = null;

          try
        {
            FileInputStream fis = new FileInputStream(fileName);
         
               InputStreamReader inStr = new InputStreamReader(fis, "UTF-8") ;
     //     InputStreamReader inStr = new InputStreamReader(fis) ;
               StringBuffer sb = new StringBuffer( );

            char[] inArray = new char [ 1024 ];

            br = new BufferedReader(inStr);
               String str = "";
            // While file contents can be read, place what's read in buffer.
            do
            {
                           
                    String str1 = br.readLine();
                   
                    System.out.println("The str1"+str1);
                    if(str1 == null)
                    {
                         break;
                    }

                    str += str1;

         
            }
            while ( true );
               System.out.println("The str"+str);

            // Return buffer as string.
           // return( sb.toString() );
             return str;
        }
        catch ( Exception ioe )
        {
            System.out.println( "ERROR: Could not read file ["+ioe);
        }
        finally   // Make sure we always close the stream.
        {
            if ( br != null )
            {
                try
                {
                    System.out.println( "Closing file." );

                    br.close( );
                }
                catch ( IOException ioe )
                {
                    System.out.println( "ERROR: Could not close file [" +
                               fileName + "]:\n\t" + ioe.toString() );
                }
            }
        }

          return "";

     }


TIA,
Madhusri.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros