FileOutputStream   out;   //   declare   a   file   output   object   
          PrintStream   p;   
          try   {   
              out   =   new   FileOutputStream(_strFilePathAndName);   
                    p   =   new   PrintStream(out);   
                    p.println   (_strLog+"\n");   
              
                    p.close();   
    
          }   
          catch   (FileNotFoundException   ex)   {   
          }   
    
    
  到是能把汉字写进去,但不能追加   
    
  用RandomAccessFile的writeBytes到可以追加,可是写汉字就不能了,全是乱码   
    
  哪位大哥还有别的办法。   

解决方案 »

  1.   

    编码问题,是不是不能用writeBytes
      

  2.   

    用FileWriter(path,true(还是false忘记了,写一下试试))
      

  3.   

    怎么转码,有例子吧?????????
    用FileWriter(path,true(还是false忘记了,写一下试试))
    不行呀
      

  4.   

    ToUniCode之类的方法, baidu搜一下: java  汉字  UniCode..
      

  5.   

    这不是汉字编码问题吧 可以追加是什么意思?
    writeBytes写进去的汉字读出来不处理肯定是乱码啊
    先看下编码的基础啊
      

  6.   

    File fDir=new File(File.separator);
    String strFile="1.txt";
    File f=new File(fDir,strFile);          
             RandomAccessFile bw=new RandomAccessFile(strFile,"rw");
             bw.seek(bw.length());//将指针移动到文件末尾 
                               String strGBK="中国";
                               bw.writeBytes(strGBK); 
                               bw.close();以上代码写进文本的是乱码,那位帮改一下,谢了.
      

  7.   

    bw.writeBytes(strGBK);    
    这也是写字节呀,
    上面我用了,写不了,不能写进呀
      

  8.   

    import java.io.*;
    public class Test{
    public static void main(String[] args){
    try {
    File fDir=new File(File.separator);
    String strFile="1.txt";
    File f=new File(fDir,strFile);
    RandomAccessFile bw=new RandomAccessFile(strFile,"rw");
    bw.seek(bw.length());//将指针移动到文件末尾
    String strGBK="中国";
    bw.write(strGBK.getBytes()) ;
    bw.close();
        }
        catch (Exception ex) {
         ex.printStackTrace();
        }

    }
    }这样写就没有问题了。
      

  9.   

    public final void writeBytes(String s)
                          throws IOException按字节序列将该字符串写入该文件。该字符串中的每个字符均按顺序写出,并丢弃其高八位。写入从文件指针的当前位置开始。 指定者:
    接口 DataOutput 中的 writeBytes
    参数:
    s - 要写入的字节的字符串。 
    抛出: 
    IOException - 如果发生 I/O 错误。丢弃了高8位,所以就写汉字就不对了。
      

  10.   

    String.getBytes();看看它,就可以了
      

  11.   

    String strFile="1.txt";
    File f =null;
    RandomAccessFile bw = null;
    try
    {
    f=new File("./"+strFile);         
    bw=new RandomAccessFile(f,"rw");
    bw.seek(bw.length());//将指针移动到文件末尾 
    String strGBK="中国";
    byte [] strBytes = strGBK.getBytes("GB2312");
    bw.write(strBytes); 

    }
    catch(IOException es)
    {
    System.out.println("IO读写异常!");
    }
    finally
    {
    try 
    {
    bw.close();
    }
    catch (IOException e) {
    System.out.println("资源回收失败!");
    }
    }楼主,编码规范些:)