以下程序可以执行,读取一个html文件,大部分的字符和中文都正常,有点问号,这是不正常显示,public static void main(String[] args) {
String path="E:/dialog";
File list=new File(path);
for(int i=0;i<list.list().length;i++){
System.out.print(list.list()[i]);
String filepath=path+"/"+list.list()[i];
String content=replaceGb2312.readcontent(filepath);
System.out.print(content);
}
}

public static String readcontent(String path){
String str=new String();
try {
FileInputStream read=new FileInputStream(path);
byte [] body=new byte[read.available()];
int i=0;

while((i=read.read(body))!=-1){
str=str+new String(body);
}
read.close();
read=null;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return str.toString();
}

解决方案 »

  1.   

    FileInputStream read=new FileInputStream(path);
    这句出问题了,你应该指定下编码,??出现了乱码,如果不做指定的话,直接调用本地的编码
      

  2.   

    如何改?replaceGb2312是我的类名,楼上的是不是看错了?
      

  3.   

    FileInputStream类的构造函数没有指定编码的,请问如何不指定编码,好不让调用本地的
      

  4.   

    另提醒一下建议使用bufferedreader
      

  5.   

    while((i=read.read(body))!=-1){
        str=str+new String(body);
    }这里的改为new String("gb2312", i);
      

  6.   

    个人建议,看看是不是要处理一下Unicode的问题?你毕竟是开字节流在读,很有可能会抓个特殊编码的东西回来。比如说,\u000A.