//OutGlobal.write(sTrExchange.toString().getBytes());//你这样已经强制使用了GB2312格式了
OutGlobal.println(sTrExchange);

解决方案 »

  1.   

    XML文件可不是这么写吧,你这样只是保存了一个扩展名为xml的文件,而不是一个XMl文件!
    要生成一个XML文件,你需要做的工作还有很多,具体操作请使用Google查找一下,JDK的帮助中也提供了相应的操作类包
      

  2.   

    用Jdon,如果想对象序列化的XML形式,应该用XMLEncoder。^_^
      

  3.   

    ChDw(米).你好我按你的方法作了,也是不行哦
    我生成的文件用记事本打开然后另存,看下面的字符集还不是utf-8郁闷...........
      

  4.   

    to:  xiaohaiz(城里的老土,两眼依然通红!) 
    我不一定要.xml的,生成.txt也可...........
    就是要生成的文件用记事本打开后另存的时候默认编码方式的UTF-8的盼赐教,感谢
      

  5.   

    不论谁解决我一定争取FAQ给加信誉分,可用分是小问题吧,呵呵
      

  6.   

    这样可以不?String tmpStr = new String(sTrExchange, "UTF-8");然后把tmpStr写到文件里
      

  7.   

    可乐啊,介个问题素很简单的,不像乃应该问出来的啊:
    <<
    String sTrExchange = "测试cccccccccceeeeeeeeeeeeeennnnnnnnnnnn";FileOutputStream fos = new FileOutputStream("D:/data.txt");
    fos.write(sTrExchange.getBytes("UTF-8"));
    fos.close();
    >>
    这样就可以了
      

  8.   

    String sTrExchange = "aaaaaaaacccccccccccccccccccceeeeeeeeeeeeeennnnnnnnnnnn";    
        BufferedWriter wr= new BufferedWriter(new FileWriter("c:\\1.txt"));    wr.newLine();
        wr.write(sTrExchange );    wr.close();
      

  9.   

    上面的我试过了,"utf-8"的不行,但是"unicode"的却可以,奇怪了
      

  10.   

    另外,俺手头正好有dom4j,用这个生成xml类似这样:
    <<
            String sTrExchange = "测试cccccccccceeeeeeeeeeeeeennnnnnnnnnnn";        Document doc = DocumentHelper.createDocument();
            Element root = doc.addElement( "root" );
            root.addText(sTrExchange);        XMLWriter writer = new XMLWriter(new FileWriter("D:/test.xml"));
            writer.write(doc);
            writer.close();
    >>
    产生的文件:
    <<
    <?xml version="1.0" encoding="UTF-8" ?> 
    <root>测试cccccccccceeeeeeeeeeeeeennnnnnnnnnnn</root> 
    >>
      

  11.   

    getBytes()有问题,是取的defaultEncoding,可以看JDK的源码
    而PrintStream(fout,false,"UTF-8");对结果没有影响
    另外close()方法自动激活了flush()修改如下:        String sTrExchange = "abcd";
            try{
                OutputStream fout= new FileOutputStream("c:/a.txt");
                java.io.PrintStream outGlobal = new java.io.PrintStream(fout);
                outGlobal.write(sTrExchange.getBytes("UTF-8"));
                outGlobal.close();
            }catch(Exception e){
                e.printStackTrace();
            }
        }
      

  12.   

    to : lenoli(可乐吧) 我的方法是肯定没有问题的,是能够很正确的以UTF-8方式输出的你不要使用记事本看,用UtrlaEdit之类的!!!!
      

  13.   

    为什么会不行?看看下面的测试程序片断,输出结果是:
    b2 e2 ca d4 
    e6 b5 8b e8 af 95 
    UTF-8 转换结果是正确的。
    =========================================================
    <<
        public static void main(String[] args) {
            String sTrExchange = "测试";        displayBytes(sTrExchange.getBytes());
            displayBytes(sTrExchange.getBytes("UTF-8"));
        }    private static void displayBytes(byte[] bs) {
            for(int i=0; i<bs.length; i++) {
                System.out.print(Integer.toHexString(bs[i]&0xFF)+" ");
            }
            System.out.print("\n");
        }
    >>
      

  14.   

    呵呵,分少了点。看看能不能申请到FAQ吧
    给各位加点信誉分