标签:rop void class org read package ati 读取 file
package Db; import java.io.InputStream; import java.util.Properties; import java.io.BufferedReader; import org.apache.log4j.Logger; import java.io.FileReader; import api.SshTest; import java.io.IOException; public class GetProperties { private static Logger logger = Logger.getLogger(SshTest.class); public static void readFile() { String driver = ""; String dburl = ""; String user = ""; String pwd=""; BufferedReader bufferedReader=null; try { bufferedReader = new BufferedReader(new FileReader("F:\\\\eclipse\\\\myproject\\\\src\\\\Db\\\\config.properties")); }catch (Exception e) { e.printStackTrace(); } Properties p = new Properties(); try { p.load(bufferedReader); } catch (IOException e1) { e1.printStackTrace(); } driver = p.getProperty("Driver"); dburl = p.getProperty("DBurl"); user = p.getProperty("DBUser"); pwd = p.getProperty("DBPwd"); System.out.println(user+pwd+dburl+driver); logger.info(""+driver+""+dburl+""+user+""+pwd); } public static void main(String[] args) { readFile(); } // Properties properties = new Properties(); // 2 // 使用ClassLoader加载properties配置文件生成对应的输入流 // 3 InputStream in = PropertiesMain.class.getClassLoader().getResourceAsStream("config/config.properties"); // 4 // 使用properties对象加载输入流 // 5 properties.load(in); // 6 //获取key对应的value值 // 7 properties.getProperty(String key); }
标签:rop void class org read package ati 读取 file
原文地址:https://www.cnblogs.com/SunshineKimi/p/10540298.html