java 读取properties文件
程序员文章站
2022-07-13 21:40:30
...
package com.fotree.yidong; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.Properties; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.remote.DesiredCapabilities; /** * Unit test for simple App. */ public class AppTest { public String getValue(String key) { String value=""; Properties prop = new Properties(); //InputStream in = getClass().getResourceAsStream("config.properties"); try { InputStream in = new BufferedInputStream(new FileInputStream("config.properties")); prop.load(in); value = prop.getProperty(key).trim(); } catch (Exception e) { e.printStackTrace(); } return value; } static { } public static void wait(int secondes) { try { Thread.sleep(secondes * 1000); } catch (InterruptedException e) { e.printStackTrace(); } } public static void main(String[] args) { AppTest pt = new AppTest(); System.out.println("username---->" + pt.getValue("username")); System.out.println("password---->" + pt.getValue("password")); System.out.println("url---->" + pt.getValue("url")); } } 这个conf.properties 在根目录,即便打成jar包也能识别 java8
上一篇: CoreJava学习心得3
下一篇: CoreJava学习笔记10