如果现在有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>
各位高手快来帮我呀!万分感谢!!!!!!
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>
各位高手快来帮我呀!万分感谢!!!!!!
<%@page pageEncoding = "gb2312" %>后就应该能正常显示了。
试试
String str=new String(fileContent.getBytes("iso-8859-1"),"gb2312");
一般认为是 "utf-8" 编码
试试
inputStream = new BufferedReader(new FileReader(txtFilename,"utf-8"));
如果是 GBK
试试
inputStream = new BufferedReader(new FileReader(txtFilename,"GBK"));