如果现在有test.xml public class test { 
public static void main(String args[]){ 
String path="test.xml"; 
StringBuffer contentBuffer =new StringBuffer(""); 
StringBuffer result=new StringBuffer(""); 
String  line=null; 
BufferedReader inputStream; 
try { 
inputStream = new BufferedReader(new FileReader(txtFilename)); 
line = inputStream.readLine(); 
while (line!=null){ 
result.append(line+'\n'); 
line = inputStream.readLine(); 

System.out.print(fileContent); 

catch (Exception e) { 
// TODO Auto-generated catch block 
e.printStackTrace(); 



但是如果test.xml中有中文的话 ,结果打印出来的就会乱码。怎样才不会乱码啊??????????就是说test.xml中有 <tp>数据提取 </tp>,那么打印出来的也是 <tp>数据提取 </tp> 
各位高手快来帮我呀!万分感谢!!!!!!

解决方案 »

  1.   

    xml的<?xml   version="1.0"   encoding="UTF-8"?>  和jsp的<%@   page   contentType=   "text/html;charset   =   gb2312"   language   =   "java"%> 都改成gb2312,然后加了一行  
    <%@page   pageEncoding   =   "gb2312"   %>后就应该能正常显示了。
      

  2.   

    还有里面有句可以改成这样 line=   new   String(line.getBytes("gb2312"));   
      

  3.   

    fileContent 哪个变量?
    试试
    String str=new String(fileContent.getBytes("iso-8859-1"),"gb2312");
      

  4.   

    或者各位高手帮我找一个可以把XML转化为txt的工具,好像单纯改名是不行的
      

  5.   

    String str=new String(fileContent.getBytes("iso-8859-1"),"utf-8");
      

  6.   

    先要确定 test.xml 使用什么编码的,如果 text.xml 的前面有 <?xml  version="1.0"  encoding="UTF-8"?> 
     一般认为是 "utf-8" 编码
    试试 
    inputStream = new BufferedReader(new FileReader(txtFilename,"utf-8")); 
    如果是 GBK 
    试试 
    inputStream = new BufferedReader(new FileReader(txtFilename,"GBK")); 
      

  7.   

    好像 要有 new InputStreamReader(new FileInputStream(file),"utf-8")
      

  8.   

    你xml生成xml时候编码  举例如果是utf-8的时候,在你这个.java文件读取的时候也设置成utf-8,没有问题,我做过
      

  9.   

    FileReader换成InputStreamReader,new的时候在第二个参数中带入文件编码就可以了。
      

  10.   

    FileReader换成InputStreamReader,new的时候在第二个参数中带入文件编码就可以了。