懒得整理了,直接复制我工程里的代码:

第一个读取文件的类可以直接复制,

不复制的话,在下面取值和赋值部分的代码new EmailProperRead(systemType).properties根据自己情况修改。

一、读取文件的类EmailProperRead(一个完整文件,可以直接复制使用):


  1. package com.uniquedu.util;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.util.Properties;
  5. import javax.servlet.http.HttpServletRequest;
  6. import org.springframework.web.context.request.RequestContextHolder;
  7. import org.springframework.web.context.request.ServletRequestAttributes;
  8. public class EmailProperRead {
  9. public String iniPath = "/WEB-INF/systemConfig.Properties"; //文件路径
  10. public Properties properties = new Properties();
  11. @SuppressWarnings("deprecation")
  12. public EmailProperRead() throws Exception{
  13. HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
  14. iniPath = request.getRealPath("/")+iniPath;
  15. File file = new File(iniPath);
  16. if(!file.exists()){
  17. file.createNewFile();
  18. }
  19. properties.load(new FileInputStream(iniPath));
  20. }
  21. }

二、取值:


  1. Properties props = new Properties(); // 获取系统环境
  2. //获取邮箱配置信息
  3. final Properties properties = new EmailProperRead().properties;
  4. //发送邮件时显示的发件人名称
  5. String personalName = properties.getProperty("emailName");
  6. // 发件人的邮箱用户名
  7. final String usernames = properties.getProperty("emailAddress");
  8. // 发件人的邮箱密码
  9. final String passwords = properties.getProperty("emailPaswd");
  10. // 邮箱服务器
  11. String host = properties.getProperty("smtpAddress");
  12. //邮件主题
  13. String mail_subject = properties.getProperty("emailTheme");

三、赋值并保存文件:


  1. Properties properties = new EmailProperRead().properties;
  2. //发送邮件时显示的发件人名称
  3. properties.setProperty("emailName", request.getParameter("emailName"));
  4. //发件人的邮箱地址
  5. properties.setProperty("emailAddress", request.getParameter("emailAddress"));
  6. //发件人的邮箱密码
  7. properties.setProperty("emailPaswd", request.getParameter("emailPaswd"));
  8. //邮箱服务器
  9. properties.setProperty("smtpAddress", request.getParameter("smtpAddress"));
  10. //邮件主题
  11. properties.setProperty("emailTheme", request.getParameter("emailTheme"));
  12. properties.store(new FileOutputStream(new EmailProperRead(systemType).iniPath),"");

最新文章

  1. Redis(二) 扩展
  2. 【自己给自己题目做】:如何在Canvas上实现魔方效果
  3. Vue.js组件示例
  4. 开发者如何利用工具快速开发出完美APP
  5. error MIDL2311 : statements outside library block are illegal in mktyplib compatability mode
  6. 输入的不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符,或者填充字符间包含非法字符
  7. GDI+
  8. 用生活例子来解释Java synchronized块
  9. 使用webview如何做超时判断
  10. 海量数据存储之Key-Value存储简介
  11. JAVA面试精选
  12. 笨办法用js屏蔽被http劫持的浮动广告
  13. shell脚本—— 字符串操作(长度,查找,替换)
  14. Session提要
  15. Python转页爬取某铝业网站上的数据
  16. centos 检测aufs 并安装
  17. mongodb 设置权限
  18. Linux中使用Electronic WeChat客户端
  19. 假期训练五(poj-1077bfs+康拓展开,hdu-2577dp)
  20. PHP关于按位取反结果的推导过程

热门文章

  1. 【例题 6-15 UVA - 10129】Play on Words
  2. IDEACould not autowire. No beans of 'xxxMapper' type found.
  3. [D3] Basic Interactivity with D3 v4
  4. LA 5902 - Movie collection 树状数组(Fenwick树)
  5. 9.7 Binder系统_c++实现_编写程序
  6. ivotal-tc-Server与Tomcat区别
  7. spark提交应用的方法(spark-submit)
  8. js进阶 12-8 如何知道上一个函数的返回值是什么(如何判断上一个函数是否执行成功)
  9. 【rlz01】完全数
  10. [CSS] Use Generated Content to Augment Information