import org.apache.log4j.logger;import java.io.file;import java.io.ioexception;import java.io.inputstream;import java.util.properties;public class ftpurlutil{ /** * 日志组件 */ private static logger logger = logger.getlogger(ftpurlutil.class.getname()); private static ftpurlutil instance = null; /** * 用于存放上传文件的目录 */ private string uploadpath; /** * 配置文件名称 */ private string configfilestring = "ftpurl.properties"; /** * 读取文件后的结果 */ private string exeresult; /** * 只允许创建一个实例对象 */ private ftpurlutil() { } /** * 创建本类的单例 * <p/> * getinstance(单例) * * @return ftpurlutil对象 */ public static ftpurlutil getinstance() { if (instance == null) { instance = new ftpurlutil(); } return instance; } /** * 读取配置文件 * * @return boolean */ public boolean readconfigfile() { //读取配置文件 inputstream inputstream = this.getclass().getclassloader().getresourceasstream(configfilestring); //读路径出错,换另一种方式读取配置文件 if (null == inputstream) { logger.error("read config file failed."); this.exeresult = "upload_read_config_file_failed"; return false; } //读取配置文件中的appid和moduleid properties p = new properties(); try { p.load(inputstream); } catch (ioexception e1) { logger.error("load config file failed." + e1); this.exeresult = "upload_load_config_file_failed"; return false; } //得到文件路径 this.uploadpath = p.getproperty("path"); //判断文件路径是否存在 try { file filepath = new file(this.uploadpath.trim()); if (!filepath.exists()) { this.exeresult = "upload_file_path_no_exist"; return false; } } catch (exception e) { logger.error("read filepath failed." + e); this.exeresult = "upload_file_path_no_exist"; return false; } return true; } public string getexeresult() { return exeresult; } public void setexeresult(string exeresult) { this.exeresult = exeresult; } public string getuploadpath() { return uploadpath; } public void setuploadpath(string uploadpath) { this.uploadpath = uploadpath; }}
详细解决方案
从web工程的src目录上读取.properties文件
热度:105 发布时间:2012-10-27 10:42:26.0
相关解决方案
- Struts 国际化 i18N properties 数据动态,该如何处理
- properties. java.io.FileNotFoundException!请高手指教!该怎么处理
- Eclipse/MyEclipse中资源文件(*properties)中输入中文保存异常解决办法
- j2me 兑现 j2se 的 Properties 功能
- 属性文件(*.properties)中如何显示中文?
- 大家帮一忙啊,如何用java程序将一个英文文件(Resources.properties)用中 ...
- 如何配置log4j.properties 才能将日志信息记录到数据库中?!!!
- CSS shorthand properties(CSS 缩写本质)
- CSS Layout Properties 格局属性
- Java API系列之util->Properties
- Configuration -Properties 资料
- Extjs4新发现02_event跟method的区别配置项(Config Options)和属性(Public Properties)的区别
- web使用中修改config.properties/xml文件,自动部署
- seam-gen 增多messages_zh_CN.properties
- java 解析 properties-运用 ResourceBundle
- properties-java web项目自定义配置文件途径
- Myeclipse “properties”选项下边"Text file encoding"选项的other选项不能手动录入编码类型
- this.getClass().getResourceAsStream("src/test.properties")为啥null值
- Myeclipse “properties”选项下部"Text file encoding"选项的other选项不能手动录入编码类型
- Eclipse/Lomboz 装 Properties Editor 插件为什么没用?该如何处理
- 请教Hibernate中怎么导入一个jdbc.properties
- struts 老是说“LocalStrings_zh.properties Not Found ”,该怎么解决
- log4j.properties,该怎么处理
- ApplicationResources.properties 文件出错,麻烦高手看看解决方法
- 请教 我用 File file = new File("\\db.properties");来找在WEB-INF里的db.properties 可以吗
- struts中为啥*properties
- properties 使用有关问题
- 配置了log4j.properties,控制台没有显示日志信息解决办法
- spring mvc properties 配置有关问题
- 用java.util.Properties能不加载"Properties"文件,而作为一个类似地图的类临时读取数据吗