使用java.util.Properties读取文件
2016-08-30 18:42
351 查看
目的 :
1、读取文件
2、管理键值内容,能够增删改查,遍历
3、能够输出或者写入文件
代码 :
package cn.com.test;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map.Entry;
import java.util.Properties;
public class TestProperty {
public static void main(String args[]) throws IOException{
String filePath = System.getProperty("user.dir")+"\\src\\pubDbConfig.properties" ;
System.out.println(System.getProperty("file.encoding"));
InputStreamReader fis = new InputStreamReader(new FileInputStream(filePath),"GBK");
Properties pro = new Properties();
pro.load(fis);
pro.list(System.out);
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
System.out.println(pro.getProperty("pub.province_name"));
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
for(Entry<Object,Object> a : pro.entrySet()){
System.out.println(a.getKey()+"=/t"+a.getValue());
}
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
pro.put("new One", "人生的风景");
for(Entry<Object,Object> a : pro.entrySet()){
System.out.println(a.getKey()+"=/t"+a.getValue());
}
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
pro.remove("new One");
for(Entry<Object,Object> a : pro.entrySet()){
System.out.println(a.getKey()+"=/t"+a.getValue());
}
}
}
结果不贴 ,不过请注意,插入后的值的位置
1、读取文件
2、管理键值内容,能够增删改查,遍历
3、能够输出或者写入文件
代码 :
package cn.com.test;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map.Entry;
import java.util.Properties;
public class TestProperty {
public static void main(String args[]) throws IOException{
String filePath = System.getProperty("user.dir")+"\\src\\pubDbConfig.properties" ;
System.out.println(System.getProperty("file.encoding"));
InputStreamReader fis = new InputStreamReader(new FileInputStream(filePath),"GBK");
Properties pro = new Properties();
pro.load(fis);
pro.list(System.out);
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
System.out.println(pro.getProperty("pub.province_name"));
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
for(Entry<Object,Object> a : pro.entrySet()){
System.out.println(a.getKey()+"=/t"+a.getValue());
}
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
pro.put("new One", "人生的风景");
for(Entry<Object,Object> a : pro.entrySet()){
System.out.println(a.getKey()+"=/t"+a.getValue());
}
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
pro.remove("new One");
for(Entry<Object,Object> a : pro.entrySet()){
System.out.println(a.getKey()+"=/t"+a.getValue());
}
}
}
结果不贴 ,不过请注意,插入后的值的位置
相关文章推荐
- 使用java.util.Properties读取配置文件信息
- java使用java.util.Properties读取properties文件的九种方法
- 读取资源属性文件(properties)java.util.ResourceBundle使用详解
- java读取配置文件(使用java.util.Properties读取)
- java.util.Properties读取中文内容的配置文件,发生中文乱码的现象有解决方案
- 通过java.util.Properties类来读取.properties文件中key对应的value
- java.util.ResourceBundle使用详解及如何调用properties文件
- 利用java.util.Properties读取属性文件
- Eclipse和Tomcat和Java读取配置文件工具类PropertiesUtil
- java IO 使用Properties设置键值对配置信息 写入文件和从文件中读取
- 解决Java读取properties文件的中文问题的新办法(不使用native2ascii.exe及其他工具)
- java 读取properties文件,运用 使用properties
- 使用java读取配置文件(ini、properties)
- 【Properties文件】Java使用Properties来读取配置文件
- Java使用properties读取配置文件
- java.util.ResourceBundle 和java.util.properties 读取配置文件区别
- Spring: 读取 .properties 文件地址,json转java对象,el使用java类方法相关 (十三)
- 使用Java的Properties类读取.properties文件
- java.util.ResourceBundle 和java.util.properties 读取配置文件区别
- java 通过 Properties 读取数据库配置 .properties 文件的使用。