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文件
热度:98 发布时间:2013-03-26 09:54:34.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"文件,而作为一个类似地图的类临时读取数据吗