package com.io.study;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Properties;
public class TestProperties {
//创建配置文件
Properties pp = new Properties();
/*
* 向配置文件中写入内容
*/
public void pushPro(){
FileOutputStream fos = null;
pp.setProperty("1", "你是谁?");
pp.setProperty("2", "who are you?");
try {
fos = new FileOutputStream("d:/test.properties");
pp.store(fos, "test");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("store successful!");
}
/*
*读取配置文件中的信息
*/
public void getPro(){
FileInputStream fis = null;
try {
fis = new FileInputStream("d:/test.properties");
pp.load(fis);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(pp.getProperty("1"));
System.out.println(pp.getProperty("2"));
}
/*
* 方法入口
*/
public static void main(String[] args) {
TestProperties tp = new TestProperties();
//tp.pushPro();
tp.getPro();
}
}
分享到:
相关推荐
java读取配置文件 在经常更换的一些东西 就可以用配置文件
在web项目中读取yml配置文件的工具类.可以实现将 server : port : portnumber : 8081 转换为 key为"server.port.portnumber",值为"8081"的Map,String>集合
java如何读取properties配置文件
使用Java读取XML配置文件
java读取properties文件的工具类,传入配置文件名字和其中的key就可以读取
利用java可以读取配置文件信息,可以流来处理这个问题
利用Java的Properties 类读取配置文件信息! 读取Properties文件的例子
JAVA读取配置文件(资源文件)源代码;JAVA读取配置文件(资源文件)源代码;JAVA读取配置文件(资源文件)源代码
java项目读取配置文件的实例代码,使用class.getClassLoader().getResourceAsStream方法。
该资源详细介绍了Java如何读取各种配置文件。如xml ini 等等
JAVA高手解析XML配置文件的读取操作.pdf
纯java底层读取配置文件,生成map,可以根据key模糊匹配查询,封装好了方法。比如getVal("spring.dubbo*url")
系统开发的时候,都会涉及到一些配置文件的读取,为方便从配置文件中读取我们预先设置的值,我做了一个简单配置文件读取工具类。这个类主要基于apache开源项目commons-configuration,附件是该工具类完整代码,仅供...
java读取、更新ini配置文件,可以分块配置
最近写一个小程序,需要读取保存在配置文件中的配置信息。 这是一个简单的例子,可以以这个程序为基础写一个完整的类出来。
在项目中我们经常要把某些常量放在配置文件中,这样修改起来会比较方便,这个工具类可以帮我们直接在java类中读取配置文件内容