读取ini文件 要读取ini文件里面的汉字,为什么读取出来的会是乱码呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ini文件是什么编码的?你是怎么读取的? BufferedReader reader = new BufferedReader(new InputStreamReader(in, charset)); String line = null; while((line = reader.readLine()) != null) { System.err.println(line); }charset utf-8, gb2312?? 我直接建的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=北京 我直接建的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=北京 记事本打开,选择另存为,编码格式选择UTF-8 windows缺省编码,好像是什么MS9xx之类的,记不清了,eclipse或者自己打印System.getPropery("file.encoding")可以看到,jvm的io编码可以通过System.getProperty("sun.io.unicode.encoding")查看问题应该就出现在编码上了,一个是读入的编码,一个是显示的编码,LZ可以参考2L的代码调整一下 你用Properties的load方法,如果文件本身不是unicode编码,最好通过native2asc工具来转换文件 我看了下,文本文件默认编码就是UTF-8,所以还是不行啊 native2ascii.exe -encoding utf8 f1 f2 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! "); } 求解 IE OLE技术 如何判断一个请求已经全部完成 关于JAVA里,流与文件的问题. 2006-12-01到2008-06-20杂遍历之间的日期??????(送高分) 关于事件响应的问题 请问有没有 日历 组件? 关于包的问题,很菜的问题 这错哪了,有人能帮我解决一下吗。 #####刚学了java有点问题请教各位高手##### 编译applet时的信息窗口 这是什么意思? 使用RequestDispatcher实现下载
你是怎么读取的?
BufferedReader reader =
new BufferedReader(new InputStreamReader(in, charset));
String line = null; while((line = reader.readLine()) != null) {
System.err.println(line);
}charset utf-8, gb2312??
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=北京
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=北京
问题应该就出现在编码上了,一个是读入的编码,一个是显示的编码,LZ可以参考2L的代码调整一下
我看了下,文本文件默认编码就是UTF-8,所以还是不行啊
native2ascii.exe -encoding utf8 f1 f2
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! ");
}