1.讀取
Properties prop = new Properties();
try {
//這個getResourceAsStream方法就是把文件轉為inputStream的方式 prop.load(HtpUtil.class.getResourceAsStream("htp.properties")); } catch (IOException e) { e.printStackTrace(); }
//獲取某個屬性 String host = prop.getProperty("host");
2.寫入
Properties prop = new Properties();
//這兒是獲取文件的絕對路徑的。
FileOutputStream fileOutputStream = new FileOutputStream(CrackHash.class.getResource("crack.properties").getFile()); prop.setProperty("cookie", "123456");
//store方法,第一個參數是輸入流,第二個是提示信息。#Sun Jan 07 18:47:58 CST 2018 prop.store(fileOutputStream, new Date().toString()); fileOutputStream.flush(); fileOutputStream.close();
這個寫入以后,在eclipse里面不一定能立刻看到,先去文件夾里用nodepad++去看一下,寫入了就是寫入了,有時候重啟了eclipse依然看不到。
