import java.util.*;
import java.io.*;
class PropertiesDemo
{
public static void main(String[] args) throws Exception
{
String url = "prop.properties";
setAndGet(url);
}
public static void setAndGet(String url) throws Exception {
File file = new File(url);
if(!file.exists()){
file.createNewFile();
}
FileInputStream fis = new FileInputStream(file);

Properties prop = new Properties();
// 从输入流中读取属性列表(键和元素对)。一定要先加载
prop.load(fis);
//往配置文件里存值,单并不会保存到配置文件中
prop.setProperty("url","localhost:8888");
//保存到配置文件中
//a.输出流
FileOutputStream fos = new FileOutputStream(file);
prop.store(fos,"配置数据库连接信息");

//得到所有的键,返回此属性列表中的键集,其中该键及其对应值是字符串,
//如果在主属性列表中未找到同名的键,则还包括默认属性列表中不同的键。
Set<String> set = prop.stringPropertyNames();
//遍历所有的key
for(String s:set){
String key = s;
String value = prop.getProperty(key);
System.out.println(key+"="+value);
}
fos.close();
fis.close();
}
}

Properties读取属性文件的更多相关文章

  1. 依据不同的操作系统读取配置文件/java读取属性文件代码

    package cn.com.css.common.util; /**  * @brief OSEnum.java 操作系统的枚举  * @attention  * @author 涂作权  * @d ...

  2. springboot 入门三- 读取配置信息二(读取属性文件方式)

    在上篇文章中简单介绍自带读取方式.springboot提供多种方式来读取 一.@ConfigurationProperties(value="my") 支持更灵活的绑定及元数据的支 ...

  3. java读取属性文件propertie中文乱码问题

    在属性文件中使用Unicode编码中文 propertie文件默认编辑就是Unicode编码

  4. Properties读取资源文件的四种方法

    package com.action; import java.io.InputStream; import java.util.Locale; import java.util.Properties ...

  5. 使用Properties读写属性文件

    import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Properties; /*Prop ...

  6. Spring读取加密属性文件处理

    引言:Spring框架俨然已经是目前Java WEB项目开发的一个宠儿,更有人将Spring, Struts,和Hibernage称之为Java WEB项目开发的3件利器.Spring的依赖.注入.A ...

  7. java下properties属性文件操作

    package cn.stat.p1.file; import java.io.File; import java.io.FileInputStream; import java.io.FileNot ...

  8. //读取配置文件(属性文件)的工具类-ConfigManager

    package com.pb.news.util; import java.io.IOException;import java.io.InputStream;import java.sql.Resu ...

  9. Spring中使用@Value读取porperties文件中的属性值方法总结及注意事项

    本文为博主原创,转载请注明出处. 此前曾总结过使用工具类读取properties文件中的属性值,有兴趣的可以看一下. 如何快速获取properties中的配置属性值:https://www.cnblo ...

随机推荐

  1. 10.并发包阻塞队列之ArrayBlockingQueue

    上一节中对并发包中的非阻塞队列ConcurrentLinkedQueue的入队.出队做了一个简要的分析,本文将对并发包中的阻塞队列做一个简要分析. Java并发包中的阻塞队列一共7个,当然他们都是线程 ...

  2. [转]如何使用BackTrack破解WIFI无线网络的WEP密钥

    aireplay-ng - -a (bssid) -h ::::: -e (essid) (interface) 你可能已经知道如果你想要加锁自己的WIFI无线网络,你最好选择WPA加密方式,因为WE ...

  3. 自己积累写的winfrom 操作api 类

    引用 类 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sys ...

  4. discuz用户登录不响应,提示nginx gateway timeout解决方法

    在使用nginx+php-cgi搭建discuz论坛过程中,出现论坛登录不响应,一直提示nginx gateway timeout504网关超时,单单采用php方式登录无问题.但因需要使用nginx把 ...

  5. python str转dict

    两种方法 捷径 eval(str) >>> user = "{'name' : 'jim', 'sex' : 'male', 'age': 18}" >&g ...

  6. python 标准库 -- requests

    一. 安装 $ pip install requests requests 并不是python 标准库, 但为了汇总方便, 将其放置于此. 二. 用法 requests.get() : GET 请求 ...

  7. 原生js二级联动

    今天说的这个是原生js的二级联动,在空白页面里动态添加并作出相对应的效果. 1 //创建两个下拉列表 select标签 是下拉列表 var sel = document.createElement(& ...

  8. css实现选项卡

    <style> *{ margin: ; padding: ; text-decoration: none; list-style: none; outline:none; } .box{ ...

  9. Redis客户端管理工具的安装及使用

    1.下载及安装 请到官网下载:www.treesoft.cn,要最新的版本treeNMS, window系统下载直接解压,就可以用了,免安装,免布署. 2.登录及连接参数配置 登录后,要配置连接参数信 ...

  10. 安装gcc提示no acceptable C compiler found in $PATH

    安装gcc提示no acceptable C compiler found in $PATH 从所报错可以看出是缺少了c编译器,因为gcc就是c编译器,所以没有安装gcc就没有c编译器. 之所以报这样 ...