要读取ini文件里面的汉字,为什么读取出来的会是乱码呢?

解决方案 »

  1.   

    ini文件是什么编码的?
    你是怎么读取的?
      

  2.   


          BufferedReader reader = 
             new BufferedReader(new InputStreamReader(in, charset));
          String line = null;      while((line = reader.readLine()) != null) {
             System.err.println(line);
          }charset utf-8, gb2312??
      

  3.   

    我直接建的txt文件改的后缀名,这是什么编码的?   Properties p = new Properties();
       FileInputStream fs = null;
              try{
              fs=new FileInputStream("./test.ini");
              p.load(fs);
              }
              catch(Exception ex){
              }     
    String AA=p.getProperty("AA");
                    System.out.println(AA);
    ini 是  AA=北京
      

  4.   

    我直接建的txt文件改的后缀名,这是什么编码的?   Properties p = new Properties();
       FileInputStream fs = null;
                  try{
                  fs=new FileInputStream("./test.ini");
                  p.load(fs);
                  }
                  catch(Exception ex){
                  }        
            String AA=p.getProperty("AA");
                    System.out.println(AA);ini 是 AA=北京
      

  5.   

    记事本打开,选择另存为,编码格式选择UTF-8
      

  6.   

    windows缺省编码,好像是什么MS9xx之类的,记不清了,eclipse或者自己打印System.getPropery("file.encoding")可以看到,jvm的io编码可以通过System.getProperty("sun.io.unicode.encoding")查看
    问题应该就出现在编码上了,一个是读入的编码,一个是显示的编码,LZ可以参考2L的代码调整一下
      

  7.   

    你用Properties的load方法,如果文件本身不是unicode编码,最好通过native2asc工具来转换文件
      

  8.   


    我看了下,文本文件默认编码就是UTF-8,所以还是不行啊
      

  9.   


    native2ascii.exe -encoding utf8 f1 f2
      

  10.   


        public static void generatorProperties() {
            File file = new File("demo");
            String path = file.getAbsolutePath();
            path = path.substring(0, path.lastIndexOf("\\")) + File.separatorChar + "src" + File.separatorChar;
            path = path
                    + GeneratorProperties.class.getPackage().getName().replace(".",
                            "/");
            System.err.println(path);
            File demo = new File(path);
            File[] files = demo.listFiles();
            Runtime run = Runtime.getRuntime();
            String toPath = path.replace("bean", "property") + File.separator;
            for (int i = 0; i < files.length; i++) {
                if (files[i].getName().endsWith(".properties")) {
                    try {
                        System.err.println(files[i].getAbsolutePath());
                        String cmd = "native2ascii.exe -encoding utf8 \""
                                + files[i].getAbsolutePath() + "\" \"" + toPath
                                + files[i].getName() + "\"";
                        System.err.println(cmd);
                        run.exec(cmd);
                    }
                    catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }        System.out.println("Properties files are generated over! ");
        }