properties可以load store

注释可以采用 "#" 或者"!"

分隔采用"="或者":"

分行采用" \"

由于property类继承的是hashtable,可以采用put putall 但是不推荐

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Properties props = new Properties();
InputStream input = new FileInputStream(new File("D:/javaDevelop/oddjob-1.4.0-SNAPSHOT-src/oddjob-src/oddjob/src/target/classes/my.properties")); props.load(input);
input.close();
System.out.println(props.getProperty("aa"));
System.out.println(props.getProperty("bb"));
System.out.println(props.getProperty("cc"));
OutputStream os =System.out;
props.storeToXML(os, "fdasfsa");
props.store(os, "putong");
props.list(System.out);
}
 package com.zuidaima;

 import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties; public class Main { public static void main(String[] args) {
Properties property = new Properties();
try {
File file = new File("c:/db.properties");
if (!file.exists()) {
file.createNewFile();
}
// 写入
property.setProperty("database", "localhost");
property.setProperty("user", "zuidaima");
property.setProperty("password", "password");
property.store(new FileOutputStream(file), null); property.load(new FileInputStream(file)); // 读取
System.out.println(property.getProperty("database"));
System.out.println(property.getProperty("user"));
System.out.println(property.getProperty("password"));
} catch (IOException e) {
e.printStackTrace();
}
}
}

properties使用的更多相关文章

  1. spring无法读取properties文件数据

    只讲述异常点,关于怎么配置文件,这里不做说明.   1. controller中无法读取config.properties文件 controller中注入的@Value配置是从servlet-cont ...

  2. Android local.properties 文件读取

    转载请标明出处:http://www.cnblogs.com/zhaoyanjun/p/6202369.html 本文出自[赵彦军的博客] 在Android Studio项目里面有个local.pro ...

  3. Crystal Clear Applied: The Seven Properties of Running an Agile Project (转载)

    作者Alistair Cockburn, Crystal Clear的7个成功要素,写得挺好. 敏捷方法的关注点,大家可以参考,太激动所以转载了. 原文:http://www.informit.com ...

  4. hibernate-mapping-3.0.dtd;hibernate-configuration-3.0.dtd;hibernate.properties所在路径

    hibernate-mapping-3.0.dtd 所在路径:hibernate-release-5.2.5.Final\project\hibernate-core\src\main\resourc ...

  5. Properties操作指南

    一.简介: Properties是java中用的比较多的一个类,表示一个持久的属性集.继承于Hashtable,Properties可从流中加载,也可保存在流中.属性列表中每个键极其对应值共同组成一个 ...

  6. Titanium.App.Properties 对象

    Titanium.App.Properties是用来管理键值对数据的一个很方便的对象.在保存数据的时候,在Ti.App.Properties.setString相对应的Key的值中设置你要保存的值即可 ...

  7. Android中使用java.util.Properties犯的错

    今天尝试使用java.util.Properties来保存应用配置,然而遇到了好几个问题,对于熟悉此内容的来说可能都是猪一样的错误,但难免有像我一样的新手再次遇到,希望此文能有所帮助. 错误1 jav ...

  8. solr定时更新索引遇到的问题(SolrDataImportProperties Error loading DataImportScheduler properties java.lang.NullPointerException)

    问题描述 报如下错误,很显然,问题原因:空指针异常: ERROR (localhost-startStop-1) [   ] o.a.s.h.d.s.SolrDataImportProperties ...

  9. 读取properties配置文件的方法

    一般在.properties文件中配置数据库连接的相关信息,我们需要从中读取信息,以便建立与数据库的连接. 文件目录: application.properties配置信息: url=jdbc:ora ...

  10. JavaSe:Properties文件格式

    Properties文件格式说明 Properties继承自Hashtable,是由一组key-value的集合. 在Java中,常用properties文件作为配置文件.它的格式是什么样的呢? 下图 ...

随机推荐

  1. JS获取图片的缩略图,并且动态的加载多张图片

    找了好多资料也没有找到该死的ie的解决办法,最后放弃了ie <!DOCTYPE html> <html> <head> <meta charset=" ...

  2. 简单记事本&Java

    目标: 学习java的IO流和文件的打开保存 内容: 使用javaSwing包里面的一些东西,比如按钮.菜单来进行布局 代码: package myNotePad; import java.awt.F ...

  3. 使用PLSQL客户端导入导出数据库

    本文主要介绍如何使用SQL Developer工具来实现备份数据库.数据导出等操作,然后实现Oracle对象导入数据等操作 1 导出数据库对象 在PL/SQL Developer的菜单Tools=&g ...

  4. ArcGIS Scalebar 比例尺 充满div

    说明:本篇博文地图充满div,上一篇博文是充满整个body 运行效果: 2.HTML代码 <!DOCTYPE html> <html> <head> <met ...

  5. 【python】-- web开发之DOM

    DOM 文档对象模型(Document Object Model,DOM)是一种用于HTML和XML文档的编程接口.它给文档提供了一种结构化的表示方法,可以改变文档的内容和呈现方式.我们最为关心的是, ...

  6. KinedEditor特性

    谷歌浏览器会将kindeditor在其他js文件加载完之后加载 kindeditor是异步加载,document.ready完了,kindeditor可能还没加载完 kind会将选区变成一个节点 1. ...

  7. iOS中成员变量和属性区别

    历史由来: 接触iOS的人都知道,@property声明的属性默认会生成一个_类型的成员变量,同时也会生成setter/getter方法. 但这只是在iOS5之后,苹果推出的一个新机制.看老代码时,经 ...

  8. [原创]java WEB学习笔记02:javaWeb开发的目录结构

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...

  9. 【leetcode刷题笔记】Substring with Concatenation of All Words

    You are given a string, S, and a list of words, L, that are all of the same length. Find all startin ...

  10. 【leetcode刷题笔记】Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. For example, ...