java属性文件读取,属性修改

/**
 * 属性文件读取
 * @author bestmata
 *
 */
public class CommUtil {

    private static Logger logger=Logger.getLogger(CommUtil.class);

    private  Properties getAttionReplyPro(){
        try {
            InputStream in=CommUtil.class.getResourceAsStream("attionReply.properties");
            Properties p=new Properties();
            p.load(in);
            in.close();
            return p;
        } catch (Exception e) {
            logger.error(e);
        }
        return null;

    }

    //获取关注的标示
    public  String getAttionFlag(){
        Properties p=getAttionReplyPro();
        String attionFlag=p.getProperty("attionFlag");
        return attionFlag;
    }

    //设置attionFlag的值
    public  void setAttionFlag(String flag){
        try {
            Properties p=getAttionReplyPro();
            p.setProperty("attionFlag", flag);
            OutputStream out=new FileOutputStream(new File(CommUtil.class.getResource("attionReply.properties").toURI()));
            p.store(out, "");
            out.flush();
            out.close();
        } catch (Exception e) {
            logger.error(e);
        }

    }

    public static void main(String[] args) {
        CommUtil a=new CommUtil();
        a.setAttionFlag("fag4");
        System.out.println(a.getAttionFlag());

    }
}
时间: 2024-08-03 18:37:10

java属性文件读取,属性修改的相关文章

8、Spring+Struts2+MyBaits(Spring注解+jdbc属性文件+log4j属性文件)

一.注解理论 使用注解来构造IoC容器 用注解来向Spring容器注册Bean.需要在applicationContext.xml中注册<context:component-scan base-package=”pagkage1[,pagkage2,…,pagkageN]”/>. 如:在base-package指明一个包 1 <context:component-scan base-package="cn.gacl.java"/> 表明cn.gacl.java包

配置文件——App.config文件读取和修改

作普通的xml文件读取的话,首先就要知道怎么寻找文件的路径.我们知道一般配置文件就在跟可执行exe文件在同一目录下,且仅仅在名称后面添加了一个.config 因此,可以用Application.ExecuteablePath+".cofig"的方式来获得,不过更加推荐使用AppDomain.CurrentDomain.SetupInformation.ConfigurationFile这句话来直接获取当前程序的配置文件的位置,具体原因,后面再叙述. 现在回过头还是看上面的这个函数,看它

Java 添加、读取、修改、删除Word文档属性

Word文档属性包括常规.摘要.统计.内容.自定义等,其中摘要包括标题.主题.作者.经理.单位.类别.关键词.备注等项目,通过设置这些摘要信息或自定义属性可方便对文档的管理.本文中将主要介绍对文档摘要信息的添加,以及读取或者编辑.删除文档中已设置的摘要信息或自定义文档信息.下面将通过Java代码详细介绍.使用工具:Free Spire.Doc for Java (免费版)Jar文件获取及导入:方法1:通过官网下载.下载后,解压,将lib文件夹下的Spire.Doc.jar文件导入java程序.方

C# xml文件读取与修改

c#读写xml文件已知有一个XML文件(bookstore.xml)如下: Code<?xml version="1.0" encoding="gb2312"?><bookstore> <book genre="fantasy" ISBN="2-3631-4"> <title>Oberon's Legacy</title> <author>Corets,

配置文件——WebApp.config文件读取和修改

[csharp] view plain copy using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Net.Mime; using System.Text; using System.Threading.Tasks; using System.Web; using System.Xml; namespace Infrastructu

SpringMVC @Value取值(取properties属性文件的属性值)

@Controller @RequestMapping("/reg") public class RegController extends BaseController { @Value("${jdbc.url}") private String signDetail; //取jdbc.url属性值

java程序文件读取与保存实例代码

1 class RadioHere extends JFrame implements ActionListener 2 { 3 private JTextArea ta=new JTextArea(10,20); 4 private JFileChooser jfc=new JFileChooser(new File(".")); 5 private JButton bOpen,bSave; 6 public RadioHere() 7 { 8 super("文档选择框应用

java web工程读取及修改配置文件

这篇博客比自己讲解的详细: http://blog.sina.com.cn/s/blog_69398ed9010191jg.html 使用方法: 1)配置文件在web-info的class目录下,或者说,eclipse工程的src目录下 2)问题:修改配置文件之后,若不重启服务器,配置文件能够即刻实时生效么?自己利用tomcat测试的结果是可以,但最好进一步确认一下 package com.bobo.util; import java.io.BufferedReader; import java

java _io_文件读取标准步骤

File f =new File("~"); //创建源InputStream is =new FileInputStream(f); //选择流is.read() 读取单个数据,并使游标下移 //操作(读取)is.close() //释放资源,输入流读取后必须释放资源 public class test{ public static void main(String[]args) { //创建源 File f=new File("C:/Users/10853/eclipse