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Á÷¹Ø±ÕµÄʱ¼äºÍ˳Ðò£¬·ñÔò¶Áд²»³É¹¦£¬ÓÈÆäÔÚ¸ÄдÊý¾ÝµÄʱºò¡£
Ïà¹ØÎĵµ£º
Javaͬ²½´úÂëתÒì²½´úÂë
Kagula
2009-11-18
ÕªÒª
Thread Thread Group
¸ÅÒª
ÀûÓÃJavaÔ´Â룬½éÉÜͬ²½´úÂëתÒì²½´úÂë¿ò¼ÜµÄʹÓã¬Ï°벿·Ý¸½¿ò¼ÜÔ´´úÂ룬ÔĶÁ±¾ÎÄ֮ǰ¿ÉÒԲο¼¡¶Java¶àÏß³Ì_±à³ÌÄ£ÐÍÑо¿¡·http://blog.csdn.net/lee353086/archive/2008/01/10/2033587.aspx
ÕýÎÄ
Tes ......
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
public class DealFile {
/**
* ɾ³ýÎļþ
......
JDK1.5ÖУ¬StringÀàÐÂÔöÁËÒ»¸öºÜÓÐÓõľ²Ì¬·½·¨String.format():
format(Locale l, String format, Object... args) ʹÓÃÖ¸¶¨µÄÓïÑÔ»·¾³¡¢¸ñʽ×Ö·û´®ºÍ²ÎÊý·µ»ØÒ»¸ö¸ñʽ»¯×Ö·û´®¡£
format(String format, Object... args) ʹÓÃÖ¸¶¨µÄ¸ñʽ×Ö·û´®ºÍ²ÎÊý·µ»ØÒ»¸ö¸ñʽ»¯×Ö·û´®¡£
¾Ù¼¸¸öÕâ¸ö·½·¨ÊµÓõÄÀý×Ó(×¢ÊÍÊÇÊä³ö½á¹û) ......
rem ¿´µ½ºÜ¶à³õѧÕß·´¸´ÎÊÕâ¸öÎÊÌ⣬дÁËÒ»¸öºÜ¼òµ¥µÄÒ»¸ö½Å±¾£¬ÓÃÓÚ×Ô¶¯ÉèÖû·¾³±äÁ¿¡£°Ñ´úÂ뿽±´£¬Áí´æΪjavaEnv.bat¡£°²×°ÍêJava 2 SDKÖ®ºó£¬¿ªÒ»¸öÃüÁîÐд°¿Ú,ÊäÈëjavaEnv java2SDKDir(java2SDKDirÊÇÄãµÄjavaµÄ°²×°Ä¿Â¼£¬²»´ø·¾¶×îºóµÄ\¡£Èç¹û°²×°Â·¾¶ÖÐÓпոñ£¬ÇëÓÃjavaEnv "java2SDKDir"¸ñʽ)²¢ÔËÐС£(×¢£ºÒ ......