JDK1.4引入了Preferences類(lèi), 用于設(shè)置用戶(hù)的首選項(xiàng)。
對(duì)于Windows平臺(tái)就是操作注冊(cè)表了, 下面的程序就可以操作注冊(cè)表了,更多請(qǐng)參考jdk的api幫助文檔。
import java.io.*;
import java.util.prefs.*;
public class PrefsDemo {
public static void main(String args[])
{
String keys[] = {"key1","key2","key3"};
String values[] = {"value1","value2","value3"};
Preferences prefsdemo = Preferences.userRoot().node("test1/test1sub1");
/* 儲(chǔ)存參數(shù)項(xiàng)*/
for (int i=0 ; i < keys.length; i++)
{
prefsdemo.put(keys[i], values[i]);
}
/*清除注冊(cè)表中的參數(shù)項(xiàng)*/
{
prefsdemo.removeNode();
}
catch (BackingStoreException e)
{}
/* 導(dǎo)出到XML文件 */
try
{
FileOutputStream fos = new FileOutputStream("prefsdemo.xml");
prefsdemo.exportNode(fos);
} catch (Exception e)
{
System.err.println("Cannot export nodes: " + e);
}
}
}
對(duì)于Windows平臺(tái)就是操作注冊(cè)表了, 下面的程序就可以操作注冊(cè)表了,更多請(qǐng)參考jdk的api幫助文檔。
import java.io.*;
import java.util.prefs.*;
public class PrefsDemo {
public static void main(String args[])
{
String keys[] = {"key1","key2","key3"};
String values[] = {"value1","value2","value3"};
Preferences prefsdemo = Preferences.userRoot().node("test1/test1sub1");
/* 儲(chǔ)存參數(shù)項(xiàng)*/
for (int i=0 ; i < keys.length; i++)
{
prefsdemo.put(keys[i], values[i]);
}
/*清除注冊(cè)表中的參數(shù)項(xiàng)*/
{
prefsdemo.removeNode();
}
catch (BackingStoreException e)
{}
/* 導(dǎo)出到XML文件 */
try
{
FileOutputStream fos = new FileOutputStream("prefsdemo.xml");
prefsdemo.exportNode(fos);
} catch (Exception e)
{
System.err.println("Cannot export nodes: " + e);
}
}
}

