properties属性文件:config.properties
#
#Tue Aug 13 15:30:56 CST 2013
timeInterval=33
name=holdOn
filepath=bb
ip=192.168.1.1
#Tue Aug 13 15:30:56 CST 2013
timeInterval=33
name=holdOn
filepath=bb
ip=192.168.1.1
类实例:Configuration.java
package example;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class Configuration {
private Properties pro;
private FileInputStream fileInputStream;
private FileOutputStream fileOutputStream;
private String filepath;
public Configuration() {
//重要内容
//重要内容
//测试地址
filepath="D:\\config.properties";
pro = new Properties();
try {
fileInputStream = new FileInputStream(filepath);
pro.load(fileInputStream);
fileInputStream.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String getfilepath() {
return filepath;
}
public String getValue(String key) {
if (pro.containsKey(key)) {
String value = pro.getProperty(key);
return value;
} else {
return "";
}
}
public void setValue(String key, String value) {
pro.setProperty(key, value);
}
public void saveFile(String fileName,String comments) {
try {
fileOutputStream = new FileOutputStream(fileName);
pro.store(fileOutputStream, "");
fileOutputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
public static void main(String[] args) {
String filename="D:\\config.properties";
Configuration conf = new Configuration();
conf.setValue("timeInterval","33");
conf.setValue("filepath","bb");
conf.saveFile(filename,"test");
String timeInterval= conf.getValue("timeInterval");
System.out.println(timeInterval);
String filepath = conf.getValue("filepath");
System.out.println(filepath);
}
}
}
提示:实例可以正常运行,重要内容(获取项目中properties文件路径)被省略,可能是您需要的,有需要的,给我发邮件,我把完整java实例打包回发给您。
我的邮箱:qmys116505@qq.com
我的邮箱:qmys116505@qq.com
相关推荐
java读写properties文件,解决系统找不到指定路径,解决写入后读取正常,但文件数据未更新问题
ava中有个比较重要的类Properties(Java.util.Properties),主要用于读取Java的配置文件,各种语言都有自己所支持的配置文件,配置文件中很多变量是经常改变的,这样做也是为了方便用户,让用户能够脱离程序本身去...
c#操作properties,读写配置文件,非常方便,几行代码就搞定
主要介绍了Java读写.properties文件解决中文乱码问题,非常具有实用价值,需要的朋友可以参考下
我们要做的第一步是要将文件读取到Properties类对象中,由于load有一个参数是InputStream,所以我们可以用 InputStream的子类FileInputStream将属性文件读取到Properties对象中,知道prop.properties的路径,我们...
在项目开发中我们会将很多环境特定的变量定义到一个配置文件中,比如properties文件,把数据库的用户名和密码存放到此属性...下面这篇文章就主要介绍了java中读写Properties属性文件公用方法,需要的朋友可以参考借鉴。
关于java 一些常用文件的读取和写入硬盘!
Java,comm是专门为Java读取串口信息的而编写的API,这个既可以读取到串口的信息,也可以进行相关数据的写入到对应的串口中。这个一般刚刚开始,使用简单的代码,进行读取的时候,可能会什么都没有发现,这个是应该,...
线程监控, dll监控, 文件监控, 注册表监控 Introduction Process Monitor is an advanced monitoring tool for Windows that shows real-time file system, Registry and process/thread activity. It combines the...
GC是垃圾收集的意思(Gabage Collection),内存处理是编程人员容易出现问题的地方,忘记或者错误的内存回收会导致程序或系统的不稳定甚至崩溃,Java提供的GC功能可以自动监测对象是否超过作用域从而达到自动回收...
GC是垃圾收集的意思(Gabage Collection),内存处理是编程人员容易出现问题的地方,忘记或者错误的内存回收会导致程序或系统的不稳定甚至崩溃,Java提供的GC功能可以自动监测对象是否超过作用域从而达到自动回收...
你可能知道在WinForm应用程序中可以利用Properties.Settings来进行类似的工作,但这些其实都利用了App.config配置文件。 本文探讨用代码的方式访问 App.config 的方法。关于 App.config 的使用远比上面提到的用途...
读取properties中存储的变量值,也可以写入properties中的变量
支持.ply文件中的常规数据,以及用于读取/写入网格数据的常用案例助手! 自动类型提升-例如,如果文件包含float字段,则可以将其无缝读取为double ! 经过测试,记录并获得MIT许可! .ply格式和 .ply格式是一种通用...
支持.ply文件中的常规数据,以及用于读取/写入网格数据的常用案例助手! 自动类型提升-例如,如果文件包含float字段,则可以将其无缝读取为double ! 经过测试,记录并获得MIT许可! .ply格式和 .ply格式是一种通用...
支持.ply文件中的常规数据,以及用于读取/写入网格数据的常用案例助手! 自动类型提升-例如,如果文件包含float字段,则可以将其无缝读取为double ! 经过测试,记录并获得MIT许可! .ply格式和 .ply格式是一种通用...