注:使用的时候需要修改文件的路径
public class PropertiesUtil {
public static void main(String[] args) throws IOException {
Map propertiesValue = getPropertiesValue();
System.out.println(propertiesValue.get("networking-mode"));
System.out.println(propertiesValue.get("replace-company"));
System.out.println(propertiesValue.get("province"));
}
public static Map getPropertiesValue() {
Map map = new HashMap();
Properties pro = new Properties();
//创建一个输出流
InputStream prois = null;
InputStreamReader pRead = null;
try {
//外部文件位置
prois = new FileInputStream(System.getProperty("user.dir") + "\\file\\wd.properties"); //乱码问题 --改
pRead = new FileReader(new File(System.getProperty("user.dir") + "\\file\\wd.properties")); //还是有乱码
//将文件取出 传入一个 输出流
pro.load(new InputStreamReader(new FileInputStream(System.getProperty("user.dir") + "\\file\\wd.properties"),"utf-8"));
map = pro;
return map;
} catch (Exception e) {
e.printStackTrace();
error(e.getMessage() + " -- ");
}
return null;
}
}