`
java_my_life
  • 浏览: 258844 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

JAVA类中实时读取properties

    博客分类:
  • JAVA
阅读更多
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;


public class Test extends Thread{
	public void run()
	{
		while(true){
			try {
				this.sleep(1000);
				readProperties();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	private static void readProperties()
	{
		Properties p = new Properties();
		try {
			InputStream in = new BufferedInputStream(new FileInputStream(Thread
					.currentThread().getContextClassLoader().getResource(
							"test.properties").getPath()));
			p.load(in);
			in.close();
			String name = p.getProperty("name");
			String id = p.getProperty("id");
			System.out.println("id=" + id + "\t name=" + name);
		} catch (Exception e1) {
			e1.printStackTrace();
		}
	}
	public static void main(String[]args)
	{
		new Test().start();
	}
}

 Properties

name=zxc
id=3zxc
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics