java基礎 讀取properties檔案

2021-08-14 00:23:42 字數 829 閱讀 1356

1.讀固定路徑的properties檔案

properties properties = new properties();

// 使用inputstream流讀取properties檔案

bufferedreader bufferedreader = new bufferedreader(new filereader("e:/path.properties"));

properties.load(bufferedreader);

//獲取key對應的value值

string a = properties.getproperty("sourcepath");

system.out.println(a);

2.讀相對路徑的properties檔案

properties properties = new properties();

// 使用classloader載入properties配置檔案生成對應的輸入流

inputstream in = main.class.getclassloader().getresourceasstream("resouces/path.properties");

// 使用properties物件載入輸入流

properties.load(in);

//獲取key對應的value值

string sourcepath = properties.getproperty("sourcepath");

string path = properties.getproperty("path");

Uiautomator讀取properties檔案

1.建立assets資料夾 工程上右鍵new folder assets folder 2.在assets資料夾中建立prop檔案 在assets資料夾中右鍵new file,輸入名稱 prop 3.在prop檔案中新增引數,格式為 key value 如 time 100 name qq 4.封裝...

java中線程讀取配置檔案properties

配置檔案在很多方面可以用到,比如資料庫連線,資料庫工廠方法的呼叫,只要在配置檔案中修改即可,不用修改程式,使用起來還是很方便的。現在演示一下通過執行緒讀取配置檔案進行反射的一種方法。在專案中新建乙個空白檔案,輸入的內容以下內容 item dao factory com.github.ven13.co...

spring父子容器與讀取properties檔案

讀取properties檔案中的內容,可以使用 value 比如 value public string url properties檔案內容是 url 但是它只能在它所在容器中使用。比如spring容器中載入了properties檔案,但你這個註解使用在springmvc容器 子容器 的contr...