Java读写修改Property文件
package com.test.common;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.Properties;
/**
* @author honglei915
* @Email cl-handsome@163.com http://blog.csdn.net/honglei915
*/
public class Data {
/**
* 指定property文件
*/
private static final String PROPERTY_FILE = "c:/data.properties";
/**
* 根据Key 读取Value
*
* @param key
* @return
*/
public static String readData(String key) {
Properties props = new Properties();
try {
InputStream in = new BufferedInputStream(new FileInputStream(
PROPERTY_FILE));
props.load(in);
in.close();
String value = props.getProperty(key);
return value;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 修改或添加键值对 如果key存在,修改 反之,添加。
*
* @param key
* @param value
*/
public static void writeData(String key, String value) {
Properties prop = new Properties();
try {
File file = new File(PROPERTY_FILE);
if (!file.exists())
file.createNewFile();
InputStream fis = new FileInputStream(file);
prop.load(fis);
fis.close();//一定要在修改值之前关闭fis
OutputStream fos = new FileOutputStream(PROPERTY_FILE);
prop.setProperty(key, value);
prop.store(fos, "Update '" + key + "' value");
fos.close();
} catch (IOException e) {
System.err.println("Visit " + PROPERTY_FILE + " for updating "
+ value + " value error");
}
}}
注意:
1可以读写property文件,而且可修改已经存在的键值对。
2应该特别注意IOl流关闭的时间和顺序,否则读写不成功,尤其在改写数据的时候。
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
淘宝用开源,微软用自己的东西,金山什么都用,Google、IBM和ORACLE以及JBOSS则全力支持OpenSource,诸多公司,我也不细评
了,从最终产品运行效率看,微软最差,Windows
Live系列的产品慢的不成样(最近几个月才略有改观),反倒是用开源的一个比一个快;看看google和淘宝。所以说,没有什么快慢,只 ......
java exception 解决方案 - 我的异常网|异常|exception|myexception 831 - ActionMessages 832 - could not instantiate id generator 833 - javax.servlet.jsp.JspException 834 - javax.naming.NoInitialContextException 835 - net.sf.hibernate.HibernateException 836 - org.hibernate.exception.GenericJDBCExceptio ......
//这是我的定时器类,用来定时执行某段任务;
package com.my.time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
public
class
BugXmlTimer {
public
......