讀取自定義的配置文件,其中的一種方式

package cn.itcast.crm.service.test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;

public class Test {
	
	public static void main(String[] args) throws FileNotFoundException, IOException {
		Properties properties = new Properties();
		FileInputStream fileInputStream = new FileInputStream(
				"src/test/java/cn/itcast/crm/service/test/test.properties");
		properties.load(fileInputStream);
		Enumeration fileName = properties.propertyNames();
		while (fileName.hasMoreElements()) {
			String key = (String) fileName.nextElement();
			String value = properties.getProperty(key);
			System.out.println(key + " , " + value);
		}
	}
}

直接創建test.properties的配置文件,copy文件的全路徑。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章