讀取properties文件
????????? ?try {???????????
?????????? File file = new File(System.getProperty("user.dir")
???????????????????????????????? + "/EMweb/WEB-INF/admininfo.properties");
??????????? InputStream is = new FileInputStream(file);
??????????? props.load(is);
??????????? this.userName = props.getProperty("userName");
??????????? this.userPassWord = props.getProperty("userPassWord");
??????????? is.close();
??????? } catch (Exception e) {
??????????? e.printStackTrace();
??????? }
????? 更改properties文件
??????? Properties prop = new Properties();
??????? File file = new File(System.getProperty("user.dir")
???????????????????????????????? + "/EMweb/WEB-INF/admininfo.properties");
??????? prop.setProperty("userName", String.valueOf(cUserName));
??????? prop.setProperty("userPassWord", String.valueOf(cUserPassWord));
??????? try {
??????????? OutputStream fos = new FileOutputStream(file);
??????????? prop.store(fos, "admininfo.properties");
??????????? fos.close();
??????? } catch (FileNotFoundException ex) {
??????????? ex.printStackTrace();
??????? } catch (IOException ex) {
??????????? ex.printStackTrace();
??????? }
這里面的關(guān)鍵是System.getProperty("user.dir") 返回當(dāng)前工作目錄
posted on 2006-05-12 15:50
Java BY 閱讀(343)
評論(0) 編輯 收藏 所屬分類:
Bo java學(xué)習(xí)筆記