1.获取系统用户目录的一个文件
2.创建文件,用Propertes类写入数据到文件
3.用Properties类读取文件的数据
public class CreateGroup extends PropertyPlaceholderConfigurer
{
public CreateGroup ()
{
init();
}
private void init()
{
try {
String path = System.getProperty("user.home")+
File.separator+"dms-group.ini";
Properties p = new Properties ();
File f = new File (path);
if (!f.exists ()||f.isDirectory ())
{
if (!f.createNewFile ())
{
System.setProperty ("groupNameLC", "groupNameLC");
return;
}
OutputStream fos = new FileOutputStream(f);
String name = "groupName"+new Date ().getTime ()+"GP";
p.setProperty ("groupNameLC", name);
p.store (fos, "######");
fos.close ();
}
InputStream in = new FileInputStream (f);
p.load(in);
String gname = p.getProperty("groupNameLC").trim();
System.setProperty ("groupNameLC", gname);
in.close ();
} catch (Exception e) {
e.printStackTrace();
}
}
}