获取的src的文件的路径乱码
问题代码
Properties pro = new Properties();
ClassLoader classLoader = JDBCUtils.class.getClassLoader();
URL res = classLoader.getResource("jdbc.properties");
String path = res.getPath();
System.out.println(path);
pro.load(new FileReader(path));
jdbc.properties文件再src目录下
解决方案
使用path = java.net.URLDecoder.decode(path,“utf-8”);
Properties pro = new Properties();
ClassLoader classLoader = JDBCUtils.class.getClassLoader();
URL res = classLoader.getResource("jdbc.properties");
String path = res.getPath();
path = java.net.URLDecoder.decode(path,"utf-8");
System.out.println(path);
pro.load(new FileReader(path));
文件路径乱码问题解决