Problem in showing chinese char from a Unicode based text file [*.txt]

Hi All!
There are some chinese characters stored in a text file [*.txt]. I'm using "Arial Unicode MS" font to show chinese in text file. The text file is showing chinese charatcres. But when I read this file and want to show each line of chinese characters. My program is showing some garbage. Here is my sample code:
//arg[0] is a unicode text file name
UIManager.put("OptionPane.messageFont", new Font("Arial Unicode MS", Font.PLAIN, 11));
String chinesesample = "\u4eac \u5582";
//this message box is showing chinese
JOptionPane.showMessageDialog(null, "Chinese Text..: " + chinesesample);
BufferedReader obj_line = new BufferedReader(new FileReader(args[0]),16);
    String data = null;
    while (obj_line.ready()) {
      data = new String(obj_line.readLine().getBytes("Unicode"));
      obj_line.readLine();
      JOptionPane.showMessageDialog(null, data);
    }But this code is not showing the exact chinese characters stored in text file.
Regards,
KS

FileReader does not support setting a charset:
http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileReader.html
Convenience class for reading character files. The constructors of this
class assume that the default character encoding and the default byte-
buffer size are appropriate. To specify these values yourself, construct
an InputStreamReader on a FileInputStream.
So our BufferedReader should be constructed from InputStreamReader on a FileInputStream.
               BufferedReader br = new BufferedReader(
                      new InputStreamReader(new FileInputStream("out.txt"), "UTF8"));Here is an example:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
// import java.io.FileReader; // no need for this
import java.io.InputStreamReader;
import javax.swing.JOptionPane;
public class DocumentRenderer{
     public static void main(String[] args){
          try{
               String chinesesample = "\u4eac \u5582\n";
               System.out.print(chinesesample);
               FileOutputStream fo = new FileOutputStream(new File("out.txt"));
               fo.write(chinesesample.getBytes("UTF8"));
               fo.close();
               BufferedReader br = new BufferedReader(
                      new InputStreamReader(new FileInputStream("out.txt"), "UTF8"));
               JOptionPane.showMessageDialog(null, "Chinese Text..: " + chinesesample);
               chinesesample = br.readLine();
               JOptionPane.showMessageDialog(null, "Chinese Text..: " + chinesesample);
               fo = new FileOutputStream(new File("out.txt"));
               fo.write(chinesesample.getBytes("UTF8"));
               fo.close();
          }catch(Exception e){
}

Similar Messages

  • How to show chinese char form db in my jsp portlet?

    How to show chinese char form db in my jsp portlet?
    I had tried to set contentType in renderResponse, but itn't work ..

    Bent,
    You can access the database from your Java portlet, just like from any other Java/JSP environment. Yes, you can use JDBC, as well as BC4J.
    The Discussion Forum portlet was built using BC4J, take a look at it's source to see how it was done.
    Also, check out Re: BC4J Java portlet anyone?, it contains a lot of useful information too.
    Peter

  • Dreamweaver encountered problems while constructing the menus from the current menus.xml file

    So, after having trouble with my Photoshop scratch disk, I had to do an archive and install of my Mac OS 10.6.1 then reinstall the Adobe suite. I then had to run the Licensing Repair Tool (http://www.adobe.com/support/contact/licensing.html).
    Now everything works but Dreamweaver, which is throwing the following error:
    "Dreamweaver encountered problems while constructing the menus from the current menus.xml file.
    Please delete the current menus.xml file and rename menus.bak to menus.xml"
    I tried that. menus.bak is a directory, not a file. Even renaming the directory didn't work.
    I saw this http://forums.adobe.com/message/2188511#2188511
    but I don't have a /FlashPlayerTrust/ directory, nor do I see what that has to do with Dreamweaver.
    I couldn't find a corresponding solution for this http://forums.adobe.com/message/862339#862339 for the Mac OS.
    This http://forums.adobe.com/message/3396334#3396334 didn't help, either.
    Anybody have any ideas?
    Thanks!

    This is the error I got after deleting (moving) the configuration directory.
    "No document types have been found in the Configuration/DocumentTypes/ folder. The MMDocumentTypes.xml file may be missing or corrupted. The application will exit now."
    I've reinstalled the entire Adobe CS4 (which fixed my Photoshop problem but created this Dreamweaver problem) and then reinstalled Dreamweaver alone.
    I've also attached a screenshot of the Dreamweaver directory tree with the menus.xml files.

  • How can I Cache the data I'm reading from a collection of text files in a directory using a TreeMap?

    How can I Cache the data I'm reading from a collection of text files in a directory using a TreeMap? Currently my program reads the data from several text files in a directory and the saves that information in a text file called output.txt. I would like to cache this data in order to use it later. How can I do this using the TreeMap Class? These are the keys,values: TreeMap The data I'd like to Cache is (date from the file, time of the file, current time).
    import java.io.*;
    public class CacheData {
      public static void main(String[] args) throws IOException {
      String target_dir = "C:\\Files";
      String output = "C:\\Files\output.txt";
      File dir = new File(target_dir);
      File[] files = dir.listFiles();
      // open the Printwriter before your loop
      PrintWriter outputStream = new PrintWriter(output);
      for (File textfiles : files) {
      if (textfiles.isFile() && textfiles.getName().endsWith(".txt")) {
      BufferedReader inputStream = null;
      // close the outputstream after the loop
      outputStream.close();
      try {
      inputStream = new BufferedReader(new FileReader(textfiles));
      String line;
      while ((line = inputStream.readLine()) != null) {
      System.out.println(line);
      // Write Content
      outputStream.println(line);
      } finally {
      if (inputStream != null) {
      inputStream.close();

    How can I Cache the data I'm reading from a collection of text files in a directory using a TreeMap? Currently my program reads the data from several text files in a directory and the saves that information in a text file called output.txt. I would like to cache this data in order to use it later. How can I do this using the TreeMap Class?
    I don't understand your question.
    If you don't know how to use TreeMap why do you think a TreeMap is the correct solution for what you want to do?
    If you are just asking how to use TreeMap then there are PLENTY of tutorials on the internet and the Java API provides the methods that area available.
    TreeMap (Java Platform SE 7 )
    Are you sure you want a map and not a tree instead?
    https://docs.oracle.com/javase/tutorial/uiswing/components/tree.html

  • Photos 1.0 not showing all images from Photos Library.photoslibrary folder/file after update install

    I installed the update that changed my iPhoto to Photos 1.0, and the new Photos program is not showing all images from Photos Library.photoslibrary file/folder (not sure to call it file or folder since it is actually a folder with all my pics but it acts more like a file) after update install.  The Photos Library.photoslibrary file/folder shows to be 55 gb in size, and it shows to be loaded into the photos program, but there are maybe a few weeks of pictures showing instead of a few years.  Lots of pictures in the 55 gb are not showing for some reason. 

    No - iPhotos has not replaced anything - it is new and an addition - iPhoto is still on your system in the applications folder and still works just fine
    Outlook is not supported by Photos - not sure if the support must come form Apple or MS as Photos uses a different interface to external packages than iphoto did
    LN

  • Data from planning cube to TEXT FILE IN directories of BW

    hi all
    i have 2 transactional planning cubes in BW. the data in these cubes in bw needs to be uploaded monthly in to a single text file so that APO system can access the data for some purpose.
    my question is how to upload the data from transactional cubes to the text file, which is more detailed. is that use ful to construct a ODS or CUBE(basic) on top of the transactional cubes.
    if i keep the file in BW directory whethere APO can access that.?..
    please help me out
    praveen.

    Hi,
    You could create a multicube over your 2 transactional cubes and extract your data with a query on the multicube.
    Make sure you restrict 0REQUID 'request id' using 0S_RQMRC 'most current data' to be sure you extract the most recently planned data.
    No need to convert the transactional cubes to basic cubes.
    To download the query I think you have to use the reporting agent of the broadcaster.
    Thanks for you points if you found this helpful or if this solved your problem.
    Best Regards,
    Filip

  • Sending data from database to a Text file..??????

    hi guys i am having trouble sending records from a database to a .txt file,
    (the database is on my local machine)
    the code so far is below, when i compile, it compiles with no problems but when i run it it gives me errors....the errors are below....
    any advice or help will be appreaciated ...tc
    =============================================================================================
    code:
    =============================================================================================
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.math.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    public class DataOut extends JFrame {
    public DataOut()
    try
    // Connect to the Database
    //connection object created using DriverManager class
    //carpark is the name of the database
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection connect =DriverManager.getConnection("jdbc:odbc:carpark");
         // Read data from a table
    String sql = "SELECT * FROM member";
    Statement stmt = connect.createStatement();
    ResultSet rset = stmt.executeQuery("SELECT dds, dss, t, s FROM member");
    String str = "";
    while (rset.next()) {
    str += rset.getInt(1)+" "+ rset.getString(2)+" "+ rset.getFloat(3)+" "+rset.getInt(4)+"n";
    byte buf[] = str.getBytes();
    OutputStream fp = new FileOutputStream("file.txt");
    fp.write(buf);
    fp.close();
    rset.close();
    stmt.close();
    connect.close();
    catch(Exception e) {
    e.printStackTrace();
    this.setSize(450,260);
    this.setLocation(500,200);
    public static void main(String[] args)
    DataOut frame = new DataOut();
    ==========================================================================================================
    ===========================================================
    error:
    ===========================================================
    C:\Users\giga\Desktop>javac DataOut.java
    C:\Users\giga\Desktop>java DataOut
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Invalid characte
    r value for cast specification on column number 1 (dds)
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
    at sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(JdbcOdbc.java:3811)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(JdbcOdbcResultSet.java
    :5638)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:583)
    at DataOut.<init>(DataOut.java:32)
    at DataOut.main(DataOut.java:54)
    C:\Users\giga\Desktop>java DataOut
    ===============================================================
    all the best..

    thx a lot it works...
    when it outputsto the txt file,, the data is all in one line...how can i seperate the output..sothat after it does one record the next record starts on a new line in the txt file...
    i know i have to edit this bit of the code but i am not sure which part...if that makes sense...
    ResultSet rset = stmt.executeQuery("SELECT dds, dss, t, s FROM member");
    String str = "";
    while (rset.next()) {
    str += "First name: "+ rset.getObject(1)+"\n" + " Second name: "+ rset.getObject(2)+" Third data: "+ rset.getObject(3)+" Fourth data: "+rset.getObject(4);
    i have tried "\n" but it seems not to work..

  • Updating equation in formula node from a string or text file

    Is it possible to have a calculation performed based on an equation stored in a string (read from a text file). I am guessing not because the equation would need be compiled but thought I would ask.

    Hi,
    it depends on how complex the equation is.
    Rather than using a formula node, you could use the eval formula node vi instead. (Functions->Analyze->Mathematics->Formula), but you may needs to re-organise the text formula a little.
    Assuming you're using not the base package, and atleast LabVIEW version 6.1 that shouldn't be a problem.
    Hope that helps.
    Sacha Emery
    National Instruments (UK)
    // it takes almost no time to rate an answer

  • Send 255 char by mail attchmnt in text file using FM 'SO_NEW_DOCUMENT_ATT

    Hi,
    I need to send some data an email attachment in a text file (notepad). However, the data exceeds 255 chars which is why most of it gets truncated.
    I am using the function module 'SO_NEW_DOCUMENT_ATT_SEND_API1'.
    Kindly provide solution for the problem. Relevant code samples would be appreciated.
    Regards,
    Smruthi.

    Hello Smrithi
    it is always good to search before you post a query in SCN
    find the below search
    http://www.sdn.sap.com/irj/scn/advancedsearch?query=emailwithmorethan255+char
    cheers
    S.Janagar

  • Upload data from Internal table to text file with  '~' separator

    can anyone help me to download data from internal table to flat file with  ''  separator. GUI_DOWNLOAD is not working in my case ....like for ''  separator

    Here it is
    REPORT  zkb_test1.
    TYPE-POOLS: truxs.
    DATA: i_scarr TYPE TABLE OF scarr,
    i_conv_data TYPE truxs_t_text_data.
    SELECT * FROM scarr INTO TABLE i_scarr.
    CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
      EXPORTING
        i_field_seperator    = '~'
      TABLES
        i_tab_sap_data       = i_scarr
      CHANGING
        i_tab_converted_data = i_conv_data
      EXCEPTIONS
        conversion_failed    = 1
        OTHERS               = 2.
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL METHOD cl_gui_frontend_services=>gui_download
      EXPORTING
        filename                = 'C:\Test1.txt'
        filetype                = 'ASC'
      CHANGING
        data_tab                = i_conv_data
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        not_supported_by_gui    = 22
        error_no_gui            = 23
        OTHERS                  = 24.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    Regards
    Kathirvel

  • Data from transaction cubes to text file in bw directories

    hi all
    i have 2 transactional planning cubes in BW. the data in these cubes in bw needs to be uploaded monthly in to a single text file so that APO system can access the data for some purpose.
    my question is how to upload the data from transactional cubes to the text file, which is more detailed. is that use ful to construct a ODS or CUBE(basic) on top of the transactional cubes.
    if i keep the file in BW directory whethere APO can access that.?..
    please help me out
    praveen.

    You can load data directly from the BW cubes to APO if the BW system is set up as a source system.
    If you need the file then you may want to investigate using open hub.

  • Want to convert the .DAQ file from MAX to a text file to be included with data runs for experiments.

    I want to take the .DAQ file from the MAX program and convert it to a text file. From my understanding this file contains all the information for the channels and hardware that is currently set up on the system. I want to use this data as a file so that others can set up the experiment again in the future and this data would be helpful. Thanks in advance for any help in regard to this matter.

    HAL;
    I'm attaching a Labview example to this answer which does that with the properties of your virtual channels configuration in MAX. Other than that, there isn't any way, at this time, to convert the .daq file to a text file.
    Hope this helps.
    Filipe
    Attachments:
    vrtchstf.zip ‏19 KB

  • Importing Data from SQL DB or Text File to Call Manager 8.5.1

    Hi Everyone,
    I would like to import from an external DB or text  file, what have you, the Employees Single reach Number to Call Manager.  Please let me know your suggestions.
    Thanks

    I don't see why not. This additional requirement would likely require you go the AXL API route so that you can remove unnecessary manual steps. If you are looking for a "trigger" event, then that would be trickier. You may be able to craft something from audit logs or tomcat logs but I don't know if that would be worth the headache. It would require some additional thought.
    You could do a scheduled sync. You will need to ensure you understand all database dependencies and account for some of the additional end user customizations (like time of day and allow lists). The database schema (data dictionary) for your version is here:
    www.cisco.com/en/US/docs/voice_ip_comm/cucm/datadict/8_5_1/datadictionary_851.pdf
    HTH.
    Regards,
    Bill
    please rate helpful posts

  • Loading data from oracle table to text file........

    how can i load data from a oracle table to a text file or CSV file using PL/SQL procedures where the pls/sql code will take the table name dynamically.........
    soumen

    Try this thread..
    Is it possible to export a pl/sql region as a csv file?

  • Reading one and one value from either excel or text file

    Hello
    We are some students working on a schoolproject where we want to control some motor outputs. We want to create a set of input-values that are being red into our program either excel or text file.
    For example we want a input to read value "1" then the program runs its course and we get a result of the input "1", after that read the next value "2" and the program runs its course and so on.
    We have searched for clues and answeres, but i guess were really bad at that. Anyone here that could help us out?
    Under you can see one of our programs, its designed to control 3 fans depending on the input (CO ppm). We want to replace the "Numeric Controller" (CO ppm) into "something else" that gives us one and one input from a list of values.
    Kindly regards
    Weary students
    Solved!
    Go to Solution.

    Hi Guys!
    Nice to see that you are using this for your school project! Below I included two Knowledge bases with the information that you need. You can learn from it and try to see if you can read something and display it, to start with. Then try looking for specific data. 
    http://digital.ni.com/public.nsf/allkb/E02847A93FD79F7486256E050070E85B?OpenDocument 
    http://digital.ni.com/public.nsf/allkb/99F61B6AB9CD6AFA8625734600814D6B?OpenDocument 
    Please let me know how this works out for you. 
    Collin de Wit
    National Instruments
    Applications Engineering

Maybe you are looking for

  • Purchase Order and Invoice in Different Currency

    Hi All Is it possible to capture an Invoice with foreign currency agianst an order created in local currency using T.Code MIRO Vishnu

  • ENTERPRIZE BACKUP UTILITY

    제품 : ORACLE SERVER 작성날짜 : 1996-11-29 1. The Problem 과거 메인 프레임 환경에서 사용하던 고객들이 저 비용, C/S환경으로 Migration시에는 주로 Open system과 Oracle RDBMS를 채택하고 있다. 이런 관계로 해당 제품 시장은 고 성장을 구가하고 있기도 하다. 이러한 고 성장을 가능케 하는 요소는 물론 H/W,S/W에서의 혁신적인 진보이나, 메인 프레임급에 걸 맞는 대용량 DB를 관리하

  • ITunes recognizes iPod but can't sync - driver missing?

    Here's the rundown. Several months ago, the complete content of the old XP machine where this iPod's library resided was migrated to a Windows 7 Home Premium system using LapLink PC Mover.  iTunes had never previously been installed on the Windows 7

  • Can't get this app to work with my flash player

    can't this app to work with my flash player

  • Will RoboHelp 7 Run in Windows 7 32-bit?

    I've seen several threads clearly state that RoboHelp 7 won't work on a Windows 64-bit machine, but I was wondering if it is possible to run it on a Windows 32-bit PC?