您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 属性文件读写(java)
  所属分类: Java
  开发工具:
  文件大小: 3kb
  下载次数: 0
  上传时间: 2008-09-03
  提 供 者: xueba*****
 详细说明: package org.fenet.javamail; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Properties; /** * @ProjectName : JavaTest * @PackageName : org.fenet.javamail * @FileName : PropertiyFileReader.java * @Describe : * @CreateTime : 2008-9-3下午04:07:01 * @Author : xuebailong(xuebailong@fenet.com.cn) */ public class PropertiyFileReader { /* * 属性文件名, 包 括路径 */ private String propertiesFileName = null; private Properties pro = null; public void setPropertiesFileName(String propertiesFileName) { this.propertiesFileName = propertiesFileName; } public PropertiyFileReader() { } public PropertiyFileReader(String propertiesFileName) { this.propertiesFileName = propertiesFileName; } /* * 根据key * 得到属性文件的值 */ public String getValueByPropertyKey(String key) { String value = null; if (checkPropertyFile()) { value = getValue(key); } return value; } /* * get Value */ private String getValue(String key) { this.pro = new Properties(); String value = null; InputStream is = getPropertyFileInputStream(); try { pro.load(is); value = pro.getProperty(key); is.close(); } catch (IOException e) { e.printStackTrace(); } return value; } /* * set Value, * comments : 注释 */ private void setValue(String key, String value, String comments){ this.pro = new Properties(); this.pro.setProperty(key, value); OutputStream os = getPropertyFileOutputStream(); try { pro.store(os, comments); os.close(); } catch (IOException e) { e.printStackTrace(); } } /* * 得到文件输入句柄 */ private InputStream getPropertyFileInputStream() { InputStream is = null; try { if (checkPropertyFile()) { is = new FileInputStream(this.propertiesFileName); } } catch (FileNotFoundException e) { e.printStackTrace(); } return is; } /* * 得到文件输出句柄 */ private OutputStream getPropertyFileOutputStream(){ OutputStream os = null; try { if (checkPropertyFile()) { os = new FileOutputStream(this.propertiesFileName); } } catch (FileNotFoundException e) { e.printStackTrace(); } return os; } /* * 检查属性文件是否被设置值 */ private boolean checkPropertyFile() { if (this.propertiesFileName == null) { return false; } return true; } /** * @MethodName : main * @Author : xuebailong(xuebailong@fenet.com.cn) * @CreateTime : 2008-7-18下午04:36:58 * @Description: * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub PropertiyFileReader pfR = new PropertiyFileReader(); pfR.setPropertiesFileName("C:/TEMP/mail.properties"); String email = pfR.getValueByPropertyKey("name"); System.out.println(email); String key = "name"; String value = "xbl"; pfR.setValue(key, value, "This is my name "); } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 属性文件读写 javaMail
 输入关键字,在本站1000多万海量源码库中尽情搜索: