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
相关解决方案
- 属性文件(*.properties)中如何显示中文?
- 如何配置log4j.properties 才能将日志信息记录到数据库中?!!!
- CSS shorthand properties(CSS 缩写本质)
- CSS Layout Properties 格局属性
- Configuration -Properties 资料
- Extjs4新发现02_event跟method的区别配置项(Config Options)和属性(Public Properties)的区别
- web使用中修改config.properties/xml文件,自动部署
- seam-gen 增多messages_zh_CN.properties
- java 解析 properties-运用 ResourceBundle
- Myeclipse “properties”选项下边"Text file encoding"选项的other选项不能手动录入编码类型
- 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
- 配置了log4j.properties,控制台没有显示日志信息解决办法
- spring mvc properties 配置有关问题
- log4j.properties DatePattern 无效 不能产生每日一日志解决方法
- 配置了log4j.properties,控制台没有显示日志信息解决方法
- 关于插件相关的两个有关问题,右键菜单的变更,properties view的刷新
- eclipse启动时,提醒无法读出log4j.properties
- properties editor插件的配备
- properties editor插件有关问题
- project-> properties(或者 右键-> build path-> configure build path
- jaxb错误 Class has two properties of the same name "username"
- properties.store()方法解决方案
- properties.store()步骤