java读取配置文件
来源:互联网 发布:android网络编程 编辑:程序博客网 时间:2024/05/24 00:46
java配置文件读取
编写java程序时难免会使用到配置文件,配置文件读取组件是一个非常常用的组件,分享一个通用的文件读取组件,以Map<String,String>存储配置文件,具体代码如下所示:
@Component("configFileReader")public class ConfigFileReader { private final Log logger = LogFactory.getLog(ConfigFileReader.class); private Map<String, String> fileContentMap = new HashMap<String, String>(); /** * readConfigFile(读取指定配置文件) *@param fileName 存放在resources目录下的配置文件 *@return 文件内容以String返回 */ public synchronized String readConfigFile(String fileName) { String fileContent = fileContentMap.get(fileName); if (fileContent == null) { String resFile = "resources/" + fileName; InputStream inputStream = null; BufferedReader in = null; try { inputStream = this.getClass().getClassLoader() .getResourceAsStream(resFile); StringBuffer sb = new StringBuffer(); in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); String line = ""; while ((line = in.readLine()) != null) { sb.append(line); } fileContent = sb.toString(); fileContentMap.put(fileName, fileContent); } catch (FileNotFoundException e) { logger.error(e); } catch (IOException e) { logger.error(e); } finally { try { if (in != null) { in.close(); } if (inputStream != null) { inputStream.close(); } } catch (IOException e) { logger.error(e); } } } return fileContent; }}
1 0
- java读取配置文件
- java读取配置文件
- java 读取properties配置文件
- Java读取properties配置文件
- JAVA读取配置文件路径
- java读取xml配置文件
- JAVA读取配置文件
- Java读取配置文件
- Java配置文件读取
- java读取xml配置文件
- java读取properties配置文件
- java 读取配置文件properties
- java读取配置文件
- Java读取配置文件
- java读取配置文件
- java读取配置文件property
- java 读取*.properties配置文件
- JAVA [ 配置文件的读取 ]
- Java JSON技术框架选型与实例
- Activity四种启动模式
- android 文字过多只想显示多行多余的文字用省略号代替和调整行间距的属性
- 解决UITableView设置了偏移量但是不偏移的问题
- radionbutton、checkbox、RatingBar自定义样式
- java读取配置文件
- tp upload
- Python开发Webservice(SOAP)
- for each循环
- eclipse插件教程之复制内容到剪贴板
- Android : assets与res/raw资源目录的区别
- android 协作项目的签名文件的问题,以后补充一下
- 抽象类和接口的区别以及使用场景(记)
- android queryIntentActivities如何寻找出某个intent是否可用