原因为:之前写的properties工具类只支持Windows平台,以下是兼容 windows和linux两个平台的 properties工具类

package com.cpcnet.util;import java.io.*;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;public class PropertiesUtil {/** * 得到某一个类的路径 *  * @param name * @return */  public static String getPath(Class name) {  String strResult = null;  if (System.getProperty("os.name").toLowerCase().indexOf("window") > -1) {  strResult = name.getResource("/").toString().replace("file:/", "")  .replace("%20", " ");  } else {  strResult = name.getResource("/").toString().replace("file:", "")  .replace("%20", " ");  }  return strResult;  }  /** * 读取所有的property * @param filename properties文件路径 * @return 所有的property的集合(map形式) */  @SuppressWarnings("unchecked")  public static Map<String, String> getPropties(String filename) {  if (null == filename) {  return null;  }  String filePath = getPath(PropertiesUtil.class) + filename;  Properties props = new Properties();  InputStream in = null;  try {  in = new BufferedInputStream(new FileInputStream(filePath));  props.load(in);  Map<String, String> map = new HashMap<String, String>();  Enumeration en = props.propertyNames();  while (en.hasMoreElements()) {  String key = (String) en.nextElement();  String Property = props.getProperty(key);  map.put(key, Property);  }  return map;  // 关闭资源  } catch (FileNotFoundException e) {  e.printStackTrace();  } catch (IOException e) {  e.printStackTrace();  } finally {  try {  in.close();  } catch (IOException e) {  // TODO Auto-generated catch block  e.printStackTrace();  }  }  return null;  }  /** * 获取某个property的值 * @param filename 文件名 * @param key  property的key * @return property的value */  public static String getProp(String filename, String key) {  if (null == filename || null == key) {  return null;  }  String filePath = getPath(PropertiesUtil.class) + filename;  Properties props = new Properties();  InputStream in = null;  try {  in = new BufferedInputStream(new FileInputStream(filePath));  props.load(in);  return props.getProperty(key);  // 关闭资源  } catch (FileNotFoundException e) {  e.printStackTrace();  } catch (IOException e) {  e.printStackTrace();  } finally {  try {  in.close();  } catch (IOException e) {  // TODO Auto-generated catch block  e.printStackTrace();  }  }  return null;  }  }

linux properties 出现java.io.FileNotFoundException相关推荐

  1. 错误:Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/db.properties]

    当在打包war时所遇到的错误: **Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [ ...

  2. java.io.file 报错_关于java.io.FileNotFoundException异常问题?

    本帖最后由 郝强勇 于 2013-3-14 16:18 编辑 下面的代码是客户端在访问servlet时,在servlet中调用数据库操作层UserDao对象中的update方法,haha.proper ...

  3. 报错信息:java.io.FileNotFoundException拒绝访问

    错误信息:(Lof4j日志文件报错) log4j:ERROR setFile(null,true) call failed. java.io.FileNotFoundException: C:my_s ...

  4. 【Java报错找不到指定文件】Exception in thread “main“ java.io.FileNotFoundException:...... (系统找不到指定的文件。)

    出错代码 (这段代码位于Src_exp2_3.java中) public static String getValue(String key) throws IOException{Propertie ...

  5. java.io.file jar_IDEA Maven 打包运行 jar java.io.FileNotFoundException: 问题?

    java.io.FileNotFoundException: D:\workspaceIdea\ywjc-refactor\target\lib\javax.annotation-api-1.3.2. ...

  6. 手机安装失败java. io_Android java.io.FileNotFoundException:*** (Permission denied)

    自从离开上海来到杭州之后,陆续接触了Android,Python,C++,OpenCV,最为一个新人来说,一路上遇到了很多坑,幸运的是 这互联网的强大(大傻子我还是蛮喜欢的哈),一路填填补补总算走了下 ...

  7. java打开文件出错_打开文件错误太多,java.io.FileNotFoundException

    在我的程序中,我有循环扫描一堆文件并读取其内容.问题发生在大约1500个文件的迭代中,似乎无法再现(或理解(由我)) 问题: java.io.FileNotFoundException: /path/ ...

  8. ApkTool反编译出错brut.common.brutexception及java.io.filenotfoundexception 之一

    反编译apk经常会遇到各种错误,smali文件出错还好,在错误信息里能看出大概哪里有了问题.但是xml文件里要是出错了就有点费劲了,很多时候抛出的错误信息是无法知道具体原因的.... 很多时候会抛出b ...

  9. springboot中getOutputStream() has already been called for this response和java.io.FileNotFoundException

    这个异常挺多人遇到的,不过我看了一下,跟我们的情况都不一样. 1.    流没关闭. 2.    未设置响应头. 3.    jsp页面需要清空流. 说一下我们遇到的情况.就是一个简单的sprinbo ...

最新文章

  1. word 流水号 自动增加_以自动组卷软件为例浅谈Python自动化办公
  2. STL源代码分析(ch 1)组态1
  3. JAVA中的设计模式三(策略模式)
  4. Java SecurityManager getThreadGroup()方法与示例
  5. 加入收藏 设为首页 代码:兼容IE和FireFox
  6. 在IIS上部署.net core的webapi项目 以及502.5错误的两种解决方法
  7. bat中获取bat命令结果
  8. 2018CUMCM(数学建模国赛)_B——智能RGV的动态调度策略
  9. PMP复习整理考点篇【9】--- 实施定性风险分析与实施定量风险分析
  10. 福师《计算机应用基础》在线作业三,福师《计算机应用基础》在线作业一 电子计算机主要以划分发展阶段.docx-得力文库...
  11. 安卓基础-day06-20180131
  12. 继昨天的猜拳游戏,升级为老虎机版
  13. 怎么把html格式转换成数字,怎么把数字转变成文本格式
  14. UDP通信,看我如何一步一步攻克面试官
  15. 水星150uh免驱版怎么安装_水星无线网卡MW150UH(免驱版)win10下的安装技巧
  16. c语言中字节数如何判断,C语言中怎样判断输入的是整数还是浮点数
  17. 使用Genexus开发开源平台的应用程序
  18. langtj牌子的机械键盘关闭闪光灯
  19. 烈焰 页游 一键端 单机自玩 架设
  20. 苹果开发者:Siri未开放API 有些让人失望

热门文章

  1. 【Java数据结构】自己实现一个HahMap(实现其put, toString, get方法)
  2. 【教程】如何给Eclipse中添加库(jar包)
  3. JDK14的新特性:Lombok的终结者record
  4. 怎么new一个指针_【译】Rust与智能指针
  5. 洛谷——P1181 数列分段Section I
  6. 浙江省第6届程序设计竞赛结题报告汇总 zoj3202-3212
  7. 2020云栖大会,宜搭发布专业开发者能力,助力政企数字化转型——阿里云开发者社区
  8. 一条SQL语句执行得很慢的原因有哪些?
  9. 用php求n个分数的和,php关于数组n个随机数分成x组,使每组值相近的算法
  10. linux测量某个ip的网速,linux下测网速