我照书上也用TRIM()没这事啊,难道真是中文的问题/

解决方案 »

  1.   

    我指的是从一个文件中读出数据用的是readLine()方法,有间隔,消不掉,用trim()没用呀
    我用的是1.3版本
    还有那个中文的问题,
    求助呀!!!!!
    谢谢
      

  2.   

    乱码问题 可以试一试改变编码在中午和en文环境下 间隔符是不同的
    trim()好像对en文环境有用吧
      

  3.   

    你往文件里写的时候把中文字符转换一下, 
    str1=new  String(str.getBytes(),"8859_1");
      

  4.   

    肯定是中文问题!
    写入时编码:(不是正好合适你的代码)
    try { 
    //下一行最最要,进行ISO-8859-1编码 
    content = new String(content.getBytes(), "ISO-8859-1"); 
    String sql = "insert into messages (content, sendtime) values (? + content + "?now())"; dbConn.executeUpdate(sql); 
    } catch(UnsupportedEncodingException e) { 
    } 读取时转换!
    String strs = new String(str.getBytes(),"GBK"); 因为你从文件中读取时用字节流的方式!只能读取低7位还是低8位(低位字节)
    我试试研究一下!
      

  5.   

    zhjjava说的极是,在对待中文或是其他的非文本文件是用字节流才能正确读取
      

  6.   

    //下面这个程序我写信息时用得是字节流写!往外读时用得是字符流!(读出中文可以正常输出)
    import java.io.*;
    public class FileOutputDemo {
     public static void main(String args[]) {
       try {
       FileOutputStream fos=new FileOutputStream("111.txt");
       DataOutputStream out=new DataOutputStream(fos);
       try {
         String str="中国";
       out.writeBytes(new String(str.getBytes(), "ISO-8859-1"));
       }
       catch(IOException e) {
       System.out.println(e);
       }
       try {
       out.close();
       }
       catch(Exception e)
       {}
       }
       catch(FileNotFoundException e) {
       System.out.println(e);
       e.printStackTrace();
      }
      try
          {
             FileReader doc = new FileReader("D:\\jdk1.3\\bin\\111.txt");
             BufferedReader buff = new BufferedReader(doc);
             String line= buff.readLine();
             while (line!=null)
             {
                 System.out.println(line);
                 line = buff.readLine();         }          buff.close();
              doc.close();
            } catch (IOException e) {
                System.out.println("Error -- " + e.toString());
             } }
    }
      

  7.   

    谢谢你们,这是我在这个论坛第一次提问
    太感谢了
    向你们致敬!!!!!!
    我爱java!