[Java]Read Properties file

package com.file.properties;

import java.io.FileInputStream;
import java.util.Properties;

public class ReadProperties {

	Properties prop;

	public ReadProperties(String path) {
		prop = new Properties();
		try{
			FileInputStream fs = new FileInputStream(path);
			prop.load(fs);
		}catch(Exception e){

		}
	}

	public String getProperty(String key) {
		return prop.getProperty(key);
	}

	public static void main(String[] args) {
		ReadProperties readProperties = new ReadProperties("D:\\SoapUIStudy\\application.properties");
		System.out.println(readProperties.getProperty("name"));
	}
}

Result :

soapUI

时间: 2024-07-30 01:21:59

[Java]Read Properties file的相关文章

java get properties file

// String title = "行政院农业委员会农粮署"; ? ? ? ? InputStream inputStream = this.getClass().getClassLoader() ? ? ? ? ? ? ? ? .getResourceAsStream("Messages.properties"); ? ? ? ? Properties properties = new Properties(); ? ? ? ? // load the inpu

Using properties file in java application

Properties files are a cool place to store your configuration details like database connection properties, error messages and other configurations for your program. You can use properties file in your application using following utility class. This c

黑马程序员——【Java基础】——File类、Properties集合、IO包中的其他类

---------- android培训.java培训.期待与您交流! ---------- 一.File类 (一)概述 1.File类:文件和目录路径名的抽象表现形式 2.作用: (1)用来将文件或文件夹封装成对象 (2)方便于对“文件”与“文件夹属性信息”进行操作 (3)File对象,可以作为参数传递给流的构造函数 (二)构造方法 * 通过File的构造函数创建File对象 方式1:File f = new File("c:\\a.txt"); 方式2:File f2 = newF

java 读取配置文件工具类 (how to read values from properties file in java)

Java 读取配置文件工具类 使用 java.util.Properties import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class PropertiesReader { private static Properties prop; static { reload(); } private static void reload() { prop = new

java读写properties文件

package tst.socket.properties; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class TestProperties {     public static void main(String[] args) throws 

Java 读写Properties配置文件

Java 读写Properties配置文件 1.Properties类与Properties配置文件 Properties类继承自Hashtable类并且实现了Map接口,也是使用一种键值对的形式来保存属性集.不过Properties有特殊的地方,就是它的键和值都是字符串类型. 2.Properties中的主要方法 (1)load(InputStream inStream)   这个方法可以从.properties属性文件对应的文件输入流中,加载属性列表到Properties类对象.如下面的代码

java解析properties文件

在自动化测试过程中,经常会有一些公用的属性要配置,以便后面给脚本使用,我们可以选择xml, excel或者json格式来存贮这些数据,但其实java本身就提供了properties类来处理properties文件,虽然名字叫properties,其实打开它发现就是一个记事本的文件,所以看起来也比较直观,下面是解析properties文件的实现代码. properties文件里存贮的样子是这样的,然后给他保存为xxx.properties即可. gsBAMUserName1=automation_

java读取.properties配置文件的几种方法

读取.properties配置文件在实际的开发中使用的很多,总结了一下,有以下几种方法(仅仅是我知道的):一.通过jdk提供的java.util.Properties类.此类继承自java.util.HashTable,即实现了Map接口,所以,可使用相应的方法来操作属性文件,但不建议使用像put.putAll这两个方法,因为put方法不仅允许存入String类型的value,还可以存入Object类型的.因此java.util.Properties类提供了getProperty()和setPr

java.util.Properties类

Properties类很常用么,几乎每个项目,从j2se到j2ee每个项目都没离开过他,就算是jsp+servlet+jdbc的东西,jdbc的配置信息也是写Properties,国际化也是Properties,cdn也是Properties,memcached也是 Properties.总之java.utils.*无所不用,不所不在.. 小记下Properties: java.util.Properties是对properties这类配置文件的映射.支持key-value类型和xml类型两种.