Java读写.properties文件实例,解决中文乱码问题
package com.lxk.propertyFileTest; import java.io.*;
import java.util.Properties; /**
* 读写properties文件测试
* <p>
* Created by lxk on 2017/4/25
*/
public class Main {
public static void main(String[] args) {
Properties prop = new Properties();
InputStream in = null;
FileOutputStream oFile = null;
try {
in = new BufferedInputStream(new FileInputStream("D:config.properties"));
//prop.load(in);//直接这么写,如果properties文件中有汉子,则汉字会乱码。因为未设置编码格式。
prop.load(new InputStreamReader(in, "utf-8"));
for (String key : prop.stringPropertyNames()) {
System.out.println(key + ":" + prop.getProperty(key));
}
//保存属性到b.properties文件
oFile = new FileOutputStream("b.properties", false);//true表示追加打开,false每次都是清空再重写 prop.setProperty("phone", "10086");
//prop.store(oFile, "此参数是保存生成properties文件中第一行的注释说明文字");//这个会两个地方乱码
//prop.store(new OutputStreamWriter(oFile, "utf-8"), "汉字乱码");//这个就是生成的properties文件中第一行的注释文字乱码
prop.store(new OutputStreamWriter(oFile, "utf-8"), "lll");
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
if (oFile != null) {
try {
oFile.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
}
}
Java读写.properties文件实例,解决中文乱码问题的更多相关文章
- JAVA本地读取文件,解决中文乱码问题
JAVA本地读取文件出现中文乱码,查阅一个大神的博客做一下记录 import java.io.BufferedInputStream;import java.io.BufferedReader;imp ...
- cocos2d-x:读取指定文件夹下的文件名称+解决中文乱码(win32下有效)
援引:http://blog.csdn.net/zhanghefu/article/details/21284323 http://blog.csdn.net/cxf7394373/article/d ...
- java properties文件转义字符和中文乱码解决
properties文件的分隔符是 =或者 : 第一次出现的就是分割符,第二次出现的也不需要转义,也即是(忽略掉[],只是着重描述字符) [\=] [\:] 或者 [=] [:] ...
- Java处理ZIP文件的解决方案——Zip4J(不解压直接通过InputStream形式读取其中的文件,解决中文乱码)
一.JDK内置操作Zip文件其实,在JDK中已经存在操作ZIP的工具类:ZipInputStream. 基本使用: public static Map<String, String> re ...
- spring使用@Value注解读取.properties文件时出现中文乱码问题的解决
解决办法 在spring中我们常常使用.properties对一些属性进行一个提前配置, spring 在读取*.properties文件时, 默认使用的是asci码, 这时 我们需要对其编码进行转换 ...
- Cocos2d-x解析XML文件,解决中文乱码
身处大天朝,必须学会的一项技能就是解决中文显示问题.这个字符问题还搞了我一天,以下是个人解决乱码问题的实践结果,希望可以给其他人一些帮助 读取xml文件代码: CCDictionary* messag ...
- php 生成读取csv文件并解决中文乱码
csv其实是文本文件,但是里面的内容是利用逗号分隔的. 1. 生成csv文件 function new_csv($arr) { $string=""; foreach ($arr ...
- java读写Properties文件
Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ...
- 用java读写properties文件的代码
package com.LY; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.F ...
随机推荐
- 让超出DIV宽度范围的文字自动显示省略号...
关键是:text-overflow: ellipsis; div.titleholder { font-family: ms sans serif, arial; font-size: 8pt; wi ...
- 在一个验证form的实例中扩展jQuery.validate
需求很简单,直接上图: 要验证表单上的3个input输入框的格式,要求如下: 主关键词情形1: 浙江 杭州 温州 主关键词情形2: 浙江|江苏|上海,但是不能用 空格和 | 混合用,也就是情形1和2不 ...
- php ajax dom---动态增加
js代码 <script type="text/javascript"> $(document).ready(function(){ $("#talk_sen ...
- 解决在SharePoint 2010/2013部署自己的Event Handler后,抛出”不能载入被引用的第三方的程序集"的问题
今天在处理客户的一个问题的时候.我们已经把我们SharePoint EventHandler依赖的第三方的TIBCO.EMS.dll注冊到GAC里面了,可是日志里面还是抛出了不能载入被引用的第三方的程 ...
- EEPlat的基于浏览器的在线开发技术
EEPlat的开发内容主要包含配置开发和基于API的扩展开发两块内容. EEPlat的配置开发基于后台的配置环境.直接通过界面操作配置就可以. EEPlat的配置平台是用EEPlat自解释构建的.本身 ...
- ubuntu14.04安装vmware workstation
0) Do the basic system installation of Ubuntu 14.04 LTS (Server or Desktop) 1) wget the installer wg ...
- js常用API汇总(转)
typeof(); 检测数据类型 String(); 转换成字符串 parseInt(); 解析出一个string或number的整数部分 parseFloat(); 解析出一个string的浮点数部 ...
- Java序列化(转载)
引用自:http://developer.51cto.com/art/201506/479979_all.htm 关于 Java 对象序列化您不知道的 5 件事 数年前,当和一个软件团队一起用 Jav ...
- RedMine Email notifications configure for MS Exchange
Boss需要用到RedMine(project management) open source. 由于不熟悉MS的SMTP服务,BOSS说他配好了,然后配置到Email notification时候, ...
- JavaScript------一元运算符+的使用
var y = "5"; // y 是一个字符串 var x = + y; // x 是一个数字 var y = "John"; // y 是一个字符串 var ...