java Properties 取文件为空或文件路径有空格的简单处理

Properties props = new Properties();
String url = this.getClass().getClassLoader().getResource(
    "config.properties").toString().substring(6);
  String empUrl = url.replace("%20", " ");// 如果你的文件路径中包含空格,是必定会报错的
  System.out.println(empUrl);
  InputStream in = null;
  try {
   in = new BufferedInputStream(new FileInputStream(empUrl));
   props.load(in);
  } catch (FileNotFoundException e1) {
   e1.printStackTrace();
  } catch (IOException e1) {
   e1.printStackTrace();
  }

你可能感兴趣的:(Java)