当成ASCII字符读进来不行吗?

解决方案 »

  1.   

    //下面程序需在jdk1.1以上使用,如果是jdk1.0,需按所述改动
    import java.io.*;public class Test3{public static void main(String args[]){try{ FileInputStream fis = new FileInputStream("Test.dat");int len = fis.available();byte[] b = new byte[len];fis.read(b);String s = new String(b);// 做 了 从GB 到Unicode 的 转换
    //如果是jdk1.0,用 String s = new String(b, 0);
    System.out.println(s); // 做 了 从Unicode 到GB 的 转 换fis.close();}catch(IOException e){}}}
    WHQ:真会灌水 :)
      

  2.   

    西文肯定没问题,中文支持吗?据我所知,JDBC就不支持中文。
      

  3.   

    jdbc支持中文,但jdbc-odbc bridge不支持中文,想我用interbase5,oracle8的pure jave driver都是支持中文的.
      

  4.   

    用filereader类应该不会有问题,或者用new String(byte[],"GB2312")
      

  5.   

    在JAVA1.1中,没有对应UNICODE的输入输出流类,只能用 String(byte[], "8859-1");解决,在1.2 中可以用Reader类解决.
      

  6.   

    Now I have a way of solute chinese problem in java 
    (include jdbc-odbc bridge but as if only fit jdk 1.1.* and 1.0.*)
    the way is using encoding way.the "iso-8859-1" encoding is the most wide english encoding solution
    supposing the chinese data is readed from file or database in String "sChData",
    you must deal with the following code 
          " byte[] ch_byte = sChData.getBytes("iso-8859-1");
           //here we force java vm to read chinese data in a english way
           sChData = new String(ch_byte);       
           //and here we force to turn into unicode data",in addition, when data writed to file or db , and use the following code
          " byte[] ch_byte = sChData.getBytes();        
          //here we divide the string into byte array        
          sChData = new String(ch_byte,"iso-8859-1");        
          //and here we force to turn to the english way from
          //  the unicode byte array" if you want to send data among threads, please use Reader/writer
    in jdk 1.1.* or jdk 1.2.* to send the unicode data which are dealt 
    with the first way;the way fit in all java editions except for jdbc in jdk1.2
    (it is only now I have not solutions.)
      

  7.   

    My code is here (use chinese params of sql to 
     read the chinese data from database):(environment :visualage for java 2.0)import java.sql.*;
    /**
     * This type was created in VisualAge.
     */
    class MyTest {
    /**
     * This method was created in VisualAge.
     * @param args java.lang.String[]
     */
    public static void main(String args[]) {
    Connection con = null;
    Statement myState = null;
    ResultSet myRSet = null;
    String url, sName;
    try {
    url = "jdbc:odbc:paper";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection(url, "", "");
    myState = con.createStatement();
    String sql = "select paperName from paper where author = \'张三\'";
    byte[] ch_Byte = sql.getBytes();
    sql = new String(ch_Byte,"iso-8859-1");
    myRSet = myState.executeQuery(sql);
    while (myRSet.next()) {
    sName = myRSet.getString("paperName");
    ch_Byte = sName.getBytes("iso-8859-1");
    sName = new String(ch_Byte);
    System.out.println("Name: " + sName);
    }
    } catch (Exception e) {
    System.out.println("error: " + e.toString());
    }
    }
    }
      

  8.   

    please the elder bother seraph send some score to me !
    I use a week in the problem.^v^