// 读取properties中的参数 Properties properties = new Properties(); // 读取properties文件 使用InputStreamReader来解决中文报错问题 InputStreamReader inputStreamReader = null; // InputStream inputStream = Main.class.getResourceAsStream("/file.properties"); // 需要遍历的路径 --在properties文件中 String path = ""; try { inputStreamReader = new InputStreamReader(Main2.class.getResourceAsStream("/file.properties"),"UTF-8"); properties.load(inputStreamReader); // 读取到properties中的参数 赋值给path path = properties.getProperty("path"); } catch (IOException e) { e.printStackTrace(); }finally { // 释放inputStream try { inputStreamReader.close(); } catch (IOException e) { e.printStackTrace(); } }
原文:https://www.cnblogs.com/CanBlog/p/11370335.html