int len=0;
byte[] b=new byte[100];
Properties pps=System.getProperties();
pps.put("file.encoding","ISO-8859-1");
FileInputStream fis=new FileInputStream("cunbin.txt");
len=fis.read(b);
System.out.println(new String(b,0,len));/*cunbin.txt存放内容:存斌*/
/*如果编码方式是ISO-8859-1,汉字应该无法输出的啊,但是我的电脑上能正常输出那两字*/
/*我用的是jdk1.6的*/

解决方案 »

  1.   

    是这样的,不知道什么原因,这个你得问sun是怎么设计JRE的.
      

  2.   

    你是在eclipse中运行的么?
    是的话请设置
    eclipse中run -- run configurations -- common -- console encoding
    这个设置决定了你eclpise中控制台字符显示
      

  3.   

    不是,只装了JDK,在命令行中显示的。
      

  4.   

    不是,只装了JDK,在命令行中显示的。
      

  5.   

    怎么能指望一句pps.put("file.encoding","ISO-8859-1");
    就能把所有文件的编码形式改过来?文件在写入时编码,写入时如果设置编码形式为latin1你写汉字进去,不用java也会发现读不出来的
      

  6.   

    要确定你的文件是以哪种编码写入的,然后读入时指定流以这种编码方式读入
    比如
    BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(reportFile), "ISO-8859-1"));
      

  7.   

    你设置的方法是错误的
    System.setProperty("file.encoding","ISO-8859-1");
    or
    Properties p = new Properties();
    p.put("file.encoding","ISO-8859-1");
    System.setProperties(p);