Encoding Problem - can't read UTF-8 file correctly

Windows XP, JDK 7, same with JDK 6
I can't read a UTF-8 file correctly:
Content of File (utf-8, thai string):
เม็ดเลือดขาว
When opened in Editor and copy pasted to JTextField, characters are displayed correctly:
String text = jtf.getText();
text.getBytes("utf-8");
-32 -71 -128 -32 -72 -95 -32 -71 -121 -32 -72 -108 -32 -71 -128 -32 -72 -91 -32 -72 -73 -32 -72 -83 -32 -72 -108 -32 -72 -126 -32 -72 -78 -32 -72 -89
Read file with FileReader/BufferedReader:
line = br.readLine();
buffs = line.getBytes("utf-8"); //get bytes with UTF-8 encoding
-61 -65 -61 -66 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
buffs = line.getBytes(); // get bytes with default encoding
-1 -2 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
Read file with:
FileInputStream fis...
InputStreamReader isr = new InputStreamReader(fis,"utf-8");
BufferedReader brx = new BufferedReader(isr);
line = br.readLine();
buffs = line.getBytes("utf-8");
-17 -65 -67 -17 -65 -67 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
buffs = line.getBytes();
63 63 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
Anybody has an idea? The file seems to be UTF-8 encoded. What could be wrong here?

akeiser wrote:
Windows XP, JDK 7, same with JDK 6
I can't read a UTF-8 file correctly:
Content of File (utf-8, thai string):
เม็ดเลือดขาว
When opened in Editor and copy pasted to JTextField, characters are displayed correctly:
String text = jtf.getText();
text.getBytes("utf-8");
-32 -71 -128 -32 -72 -95 -32 -71 -121 -32 -72 -108 -32 -71 -128 -32 -72 -91 -32 -72 -73 -32 -72 -83 -32 -72 -108 -32 -72 -126 -32 -72 -78 -32 -72 -89 These values are the bytes of your original string "เม็ดเลือดขาว" utf-8 encoded with no BOM (Byte Order Marker) prefix.
>
Read file with FileReader/BufferedReader:
line = br.readLine();
buffs = line.getBytes("utf-8"); //get bytes with UTF-8 encoding
-61 -65 -61 -66 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
buffs = line.getBytes(); // get bytes with default encoding
-1 -2 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
Read file with:
FileInputStream fis...
InputStreamReader isr = new InputStreamReader(fis,"utf-8");
BufferedReader brx = new BufferedReader(isr);
line = br.readLine();
buffs = line.getBytes("utf-8");
-17 -65 -67 -17 -65 -67 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
buffs = line.getBytes();
63 63 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14 These values are the bytes of your original string UTF-16LE encoded with a UTF-16LE BOM prefix.
This means that there is nothing wrong (the String has been read correctly) with the code and that your default encoding is UTF-16LE .
Edited by: sabre150 on Aug 1, 2008 5:48 PM

Similar Messages

  • I have the latest downloadable version of LR5.  It crashed while it was createing 1:1 previews during an import. After a Win7(64) restart, it shows a message that LR needs to quit because it can't read the preview files and it will try to fix it the next

    I have the latest downloadable version of LR5.  It crashed while it was createing 1:1 previews during an import. After a Win7(64) restart, it shows a message that LR needs to quit because it can't read the preview files and it will try to fix it the next time is launches.  I get the same message the next and every subsequent time it launches so I can't launch LR at all now.
    I get that the preview file got corrupted somehow.  Is there some way to fix this problem without building a new catalog?

    Use Windows Explorer to open the folder containing your catalog. You will see a folder with the extension .lrdata. You need to delete that folder and then start Lightroom again. Lightroom will generate a new previews folder.

  • How can one  read a Excel File and Upload into Table using Pl/SQL Code.

    How can one read a Excel File and Upload into Table using Pl/SQL Code.
    1. Excel File is on My PC.
    2. And I want to write a Stored Procedure or Package to do that.
    3. DataBase is on Other Server. Client-Server Environment.
    4. I am Using Toad or PlSql developer tool.

    If you would like to create a package/procedure in order to solve this problem consider using the UTL_FILE in built package, here are a few steps to get you going:
    1. Get your DBA to create directory object in oracle using the following command:
    create directory TEST_DIR as ‘directory_path’;
    Note: This directory is on the server.
    2. Grant read,write on directory directory_object_name to username;
    You can find out the directory_object_name value from dba_directories view if you are using the system user account.
    3. Logon as the user as mentioned above.
    Sample code read plain text file code, you can modify this code to suit your need (i.e. read a csv file)
    function getData(p_filename in varchar2,
    p_filepath in varchar2
    ) RETURN VARCHAR2 is
    input_file utl_file.file_type;
    --declare a buffer to read text data
    input_buffer varchar2(4000);
    begin
    --using the UTL_FILE in built package
    input_file := utl_file.fopen(p_filepath, p_filename, 'R');
    utl_file.get_line(input_file, input_buffer);
    --debug
    --dbms_output.put_line(input_buffer);
    utl_file.fclose(input_file);
    --return data
    return input_buffer;
    end;
    Hope this helps.

  • Can we read a ZIP file through ESB file adapter?

    Hi,
    Is it possible to read a ZIP file from a specified locaiton either through a FTP adapter or file adapter as a opaque element and place it in another specified locaiton?
    So far the available options are to read a txt, csv, fixed length or cobol file.
    I tried to create a ESB reading ZIP file and place it in another locaiton. but it was not reading the ZIP file.
    Is it first possible for the ESB to read the ZIP file? if so then is there any specific configuratuion that we have to do for it to work?

    how can we read a MSWORD file through java?You can read it like any other file using FileInputStream
    and similar.
    Howvere, if you want do do something with it, like display
    it, you have a problem. AFAIK Microsoft do not release
    information about their document formats, and i have not
    seen a .doc viewer for java.

  • Can Mac read a dcr file made with win?

    Hello,
    Can Mac read a dcr file made with win?
    Thanks in advance.

    Thanks Sean,
    I posted the question because of some problem of user to read the web page with dcr.
    You assumed right, it is e dcr hosted in a browser page and viewed via shockwave with safari.
    I don't know the nature of the problem but the user get an error.
    Maybe I must decide to buy a mac and do some test.
    Thank you again.

  • After updating os to 10.9.1can't open pdf files.  I get a message saying It may be damaged or use a file format that Preview doesn't recognise. I can still read older saved files but no new ones arriving by email.  Any help would be appreciated.

    After updating os to OSX 10.9.1 I can't open any new pdf files.  I get a message saying It may be damaged or use a file format that Preview doesn’t recognise. I can still read older saved files but no new ones arriving by email.  Also can't attach a pdf to an email to send out.  Any help would be appreciated.

    Back up all data before making any changes. Please take each of the following steps until the problem is resolved.
    Step 1
    If Adobe Reader or Acrobat is installed, and the problem is just that you can't print PDF's displayed in Safari, you may be able to print by moving the cursor to the the bottom edge of the page, somewhere near the middle. A black toolbar may appear under the cursor. Click the printer icon.
    Step 2
    There should be a setting in its preferences of the Adobe application such as Display PDF in Browser. I don't use those applications myself, so I can't be more precise. Deselect that setting, if it's selected.
    Step 3
    If you get a message such as ""Adobe Reader blocked for this website," then from the Safari menu bar, select
    Safari ▹ Preferences... ▹ Security
    and check the box marked
    Allow Plug-ins
    Then click
    Manage Website Settings...
    and make any required changes to the security settings for the Adobe PDF plugin.
    Step 4
    Triple-click anywhere in the line of text below on this page to select it, the copy the selected text to the Clipboard by pressing the key combination command-C:
    /Library/Internet Plug-ins
    In the Finder, select
    Go ▹ Go to Folder
    from the menu bar, or press the key combination shift-command-G. Paste into the text box that opens (command-V), then press return.
    From the folder that opens, move to the Trash any items that have "Adobe" or “PDF” in the name. You may be prompted for your login password. Then quit and relaunch Safari.
    Step 5
    The "Silverlight" web plugin distributed by Microsoft can interfere with PDF display in Safari, so you may need to remove it, if it's present. The same goes for a plugin called "iGetter," and perhaps others — I don't have a complete list. Don't remove Silverlight if you use the "Netflix" video-streaming service.
    Step 6
    Do as in Step 4 with this line:
    ~/Library/Internet Plug-ins
    If you don’t like the results of this procedure, restore the items from the backup you made before you started. Relaunch Safari.

  • Can't Read from Source File

    Hi Guys
    I'm using PPr CS5 on Win7 64bit.
    I'm not sure if this is strictly for here but can I pick your brains please? I edited in PPr and exported three versions of the same video to AVI (mainly different intros and titles) and they all play fine. I back up my movies to an external disk but one of them always creates an error in the back-up "Can't Read from Source File". The file sizes are 5.3gb for the offending movie and 8.3 for the other two.
    I know the answer is to re-export the movie but I'm just trying to get a bit of a handle what could have caused this problem in the first place and if this is a common problem?
    Any views?
    Regards,
    Graham

    That doesn't help much.  What exactly are you doing when you get the error message?
    Are you trying to open a PP project which contains the file?
    Are you trying to play a sequence which has clips from that file?
    Are you trying to play it in a media player?
    Are you trying to import the file into PP?

  • How can I read the bootstrap files and extract the fragment-URLs and fragment-numbers in plain text?

    How can I read the bootstrap files of any HDS Live stream and extract the fragment-URLs and fragment-numbers in plain text?
    Could it be that it is some kind of compressed format in the bootstrap? Can I uncompress it wirh  f4fpackager.exe? Could not find any download for f4fpackager.exe. I would prefere less code to do so. Is there something in Java of JavaScript, that can extract the fragment-numbers?
    Thank you!

    Doesn't sound too hard to me. Your class User (the convention says to capitalize class names) will have an ArrayList or Vector in it to represent the queue, and a method to store a Packet object into the List. An array or ArrayList or Vector will hold the 10 user objects. You will find the right user object from packet.user_id and call the method.
    Please try to write some code yourself. You won't learn anything from having someone else write it for you. Look at sample code using ArrayList and Vector, there's plenty out there. Post in the forum again if your code turns out not to behave.

  • How can i read local excel file into internal table in webdynpro for abap a

    Could someone tell me how How can i read local excel file into an internal table in webdynpro for abap application.
    thank u for your reply

    Deep,
    File manuplations...............................
    1. At the presentation level:
    ->GUI_UPLOAD
    ->GUI_DOWNLOAD
    ->CL_GUI_FRONTEND
    2. At the application server level:
    ->OPEN DATASET : open a file in the application server for reading or writing.
    ->READ DATASET : used to read from a file on the application server that has been opened for reading
    -> TRANSFER DATASET : writing data to a file.
    -> CLOSE DATASET : closes the file
    -> DELETE DATASET : delete file
    If file is on the local PC,use the function module GUI_UPLOAD to upload it into an internal table by passing the given parameters......
    call function 'GUI_UPLOAD'
    exporting
    filename = p_file
    filetype = 'ASC'
    has_field_separator = '#'
    tables
    data_tab = t_data
    p_file : excel file path.
    t_data : internal table
    <b>reward points if useful.</b>
    regards,
    Vinod Samuel.

  • With Lightroom 4 I can't read any .DNG files directly into Photoshop CS. I have camera raw 2.4

    With Lightroom 4 I can't read any .DNG files directly into Photoshop CS. I have"camera raw 2.4" selected in LR and the Plug-in for CS is Camera Raw.8BI.
    Any suggestions on what to do? Thanks.

    Welcome to the Apple Discussions. Have you tried a different DNG converter? Adobe released Adobe DNG Converter 5.3 in March of this year. Maybe, if it supports your camera, this version will create a more compatible file.

  • Why can't read access log file in real-time? (Oracle Weblogic Server 10.3)

    We can't read access log file in real-time. If access log is rotation to new file so can read access log file but can't read real-time.
    *** Oracle Weblogic Server versions 10 R3

    what's your meaning? try this command "tail -f access.log".
    Threre is a buffer about 8K for WebLogic to write the access info into the log files, so you can't see the access info untill the buffer is full.

  • Can not read my pdf files can i use adobe ?

    I can not read my pdf files and need to download adobe ,can you help please .

    In order to read the pdf either you need Acrobat or Adobe Reader,
    Acrobat is a paid software and used to read and edit the pdf files.
    Reader is the free software used to just read the pdf files.
    To download reader use this link:- http://get.adobe.com/reader/

  • How can I read the EXCEL file while Program is running in background.

    Hi all Expert,
    How can I read the EXCEL file while Program is running in background.
    Thanks

    you need to place ur excel file on application server and follow this thread: Reading an Excel file from the application server?
    loots of information if you can search forum.. thanks

  • How can I read from a file line by line?

    Hi!
    Could someone post some code or explain how can I read from a file, and want I to read a line each time. How can I go to line number N?
    Thanks

    hi,
    u can try this:
    try     {
          // open text file
          BufferedReader in = new BufferedReader(new FileReader(fileName));
          String line=in.readLine();
          while((line=in.readLine()) != null) {
          System.out.println(line);
          }The go to line number N i m not so sure.
    Cheers
    Jerry

  • .ics file error : "iCal can't read this calendar file."

    I would like to add my flight itinery to my iCal. Downloaded the .ics file from the BA website. When double clicking on it and dragging it to iCal this message pops up: "iCal can’t read this calendar file. No events have been added to your iCal calendar."
    file details:
    BEGIN:VCALENDAR
    PRODID:-//Ben Fortuna//iCal4j 1.0//EN
    VERSION:2.0
    CALSCALE:GREGORIAN
    METHOD:PUBLISH
    BEGIN:VEVENT
    I also tried converting it to .vcs. Then iCal asks which calender I would like to add it to but still comes up with above message.
    Any ideas?
    Thanks.

    Hi!
    I managed to import the file when I deleted everything that had to do with HTML code at the end of the file. I'm not exactly sure about the purpose of this code, but deleting it left me with my flights inside my calendar, exactly as I wanted.
    HTH,
    Michael

Maybe you are looking for

  • My Original 3g iPhone isn't recognized by iTunes

    When I plug in my original 3G iPhone, iTunes doesn't recognize it; therefore, I can't sync or update the music/apps. Thoughts?

  • Urgent  ! Help in linking Work center to goods movement

    hello, i need help in finding the work center for the goods movement in AUFM.  The goods movement AUFM table shows all the goods movement entries but i want to tag it to the corresponding work center. i found out a way to tag it. by linking AFKO - RE

  • Is there a Blackberry Desktop Software for MAC OS 10.4.11? Or something equivalent? Help Please!

    Hello All, Is there a Blackberry Desktop Software for MAC OS 10.4.11?  Or something equivalent? I recently switched from a palm treo to blackberry but didn't anticipate syncing issues with my mac until now.  The current BB desktop software seems only

  • BOM Sortstring field

    Hi All PP Gurus, Can you please help me in the following issue. Its very urgent please help me in this case. On the BOM master, we put the sorting string on the sortstring field. assume we put all the bom components into the same phase,but the proces

  • Output withholding tax in Purchase Order

    Dear, We are now going to start using withholding tax function but meet some problems; Withholding Tax Code is now set on vendor master, but seems not be able to output on purchase order. Is there any way  to output withholding tax code and withholdi