package My; |
import java.io.FileInputStream; |
import java.io.FileOutputStream; |
import java.io.IOException; |
import java.util.ArrayList; |
import java.util.HashMap; |
import java.util.Properties; |
public class PropertiesUtils |
{ |
static String proPath = "src/my/conf.properties" ; |
static Properties pro = null ; |
static ArrayList<String> list = new ArrayList<String>(); |
HashMap<String, String> map = new HashMap(); |
static public void ReadProperties() |
{ |
pro = new Properties(); |
FileInputStream in; |
try |
{ |
in = new FileInputStream(proPath); |
pro.load(in); |
in.close(); |
} |
catch (IOException e) |
{ |
e.printStackTrace(); |
} |
} |
static public void WriteProperties(String key, String value) |
{ |
try |
{ |
FileOutputStream oFile = new FileOutputStream(proPath, false ); // true表示追加打开 |
pro.setProperty(key, value); |
pro.store(oFile, "test" ); |
oFile.close(); |
} |
catch (IOException e) |
{ |
e.printStackTrace(); |
} |
} |
public static void main(String[] args) |
{ |
ReadProperties(); |
WriteProperties( "城市" , "洛阳" ); |
} |
} |
by: 发表于:2017-06-21 17:24:31 顶(0) | 踩(0) 回复
??
回复评论