- 浏览: 1401258 次
- 性别:
- 来自: 北京
-
文章分类
- 全部博客 (328)
- JSF (27)
- 生活 (12)
- Ajax (26)
- Maven (6)
- CSS (1)
- Shale (3)
- SiteMesh (1)
- Ext (15)
- JMX (2)
- Windows技巧 (7)
- 工作感悟 (18)
- SVN (2)
- SVG (0)
- GoogleGear (0)
- RAP (2)
- SOA与WebService (3)
- 笔记本技术研究 (1)
- Microsoft (2)
- 英语学习 (3)
- PHP (7)
- web 2.0 (6)
- 语义Web (1)
- IT史话 (3)
- iText (3)
- JVM (1)
- PropertiesEditor (1)
- J2SE (33)
- Spring (2)
- Java Batch (1)
- log (2)
- Struts2 (2)
- DWR (0)
- JAAS (3)
- EJB3 (4)
- Flex (8)
- JFreeChart (1)
- WAS (0)
- 数据库 (2)
- 摄影 (0)
- SQL (1)
- Google App Engine (1)
- linux (5)
- Eclipse plugin (10)
- Testing (0)
- Portal (0)
- 移动互联网 (0)
- SWTBot (1)
最新评论
-
江奇缘:
不错!!!!!!
web.xml里<filter-mapping>中的<dispatcher>作用 -
yy8093:
commonj 第三步,那个调用的方法要在哪里调?servle ...
JAVA中多种计时器的比较与分析 -
di1984HIT:
学习了,不错~
web.xml里<filter-mapping>中的<dispatcher>作用 -
penkee:
com.lowagie.text.DocumentExcept ...
iText中输出 中文 -
氵壞男亼乀:
我想请问下 你哪个html里面引入的几个js文件没看懂!你 ...
DWR入门教程之HelloWorld
Version 0.2 Copyright © 2007 Lars Vogel 16.10.2004 Abstract This article gives a introduction into the Java Preference API which is available since Java 1.4. The Java Preferences API provides a systematic way to handle user and system preference and configuration data, e.g. to save user settings, remember the last value of a field etc. Information saves with the Java Preference API is stored on the local machine of the user and is available to be re-used in the program, e.g. after a restart of the program. This Java Preferences API is not indented to save application data. The Java Preference API removes the burden from the individual programmer to write code to save configuration values on the different platforms his program may be running. Table of Contents The Preferences API provides a systematic way to handle program preference configurations, e.g. to save user settings, remember the last value of a field etc. Preferences are key / values pairs where the key is an arbitrary name for the preference. The value can be a boolean, string, int of another primitive type. Preferences are received and saved by get and put methods while the get methods also supply a default value in case the preferences is not yet set. java.util.prefs.Preferences can be easily used. You have to define a node in which the data is stored. Then you can call the getter and setter methods. The second value is the default value, e.g. if the preference value is not set yet, then this value will be used. Create the following program. Run the program twice. The value of "ID1" should be still true as we delete it. The value of "ID2" and "ID2" should have changed after the first call. Thank you for practicing with this tutorial. For questions and discussion around this article please use the www.vogella.de Google Group . Also if you note an error in this article please post the error and if possible the correction to the Group.
import java.util.prefs.Preferences;
public class PreferenceTest {
private Preferences prefs;
public void setPreference() {
// This will define a node in which the preferences can be stored
prefs = Preferences.userRoot().node(this.getClass().getName());
String ID1 = "Test1";
String ID2 = "Test2";
String ID3 = "Test3";
// First we will get the values
// Define a boolean value
System.out.println(prefs.getBoolean(ID1, true));
// Define a string with default "Hello World
System.out.println(prefs.get(ID2, "Hello World"));
// Define a integer with default 50
System.out.println(prefs.getInt(ID3, 50));
// Now set the values
prefs.putBoolean(ID1, false);
prefs.put(ID2, "Hello Europa");
prefs.putInt(ID3, 45);
// Delete the preference settings for the first value
prefs.remove(ID1);
}
public static void main(String[] args) {
PreferenceTest test = new PreferenceTest();
test.setPreference();
}
}
Tip
发表评论
-
百万级访问量网站的技术准备工作
2010-12-29 19:35 1476当今从纯网站技术上来说,因为开源模式的发展,现在建一个小 ... -
Java EE Productivity Report 2011
2010-12-21 17:02 1646What happens when over 1000 J ... -
An Introduction to LDAP
2010-04-13 16:24 1054An Introduction to LDAP Mich ... -
Java Interface 是常量存放的最佳地点吗?
2009-08-21 18:21 1269由于java interface中声明 ... -
Java的内存泄漏
2009-08-20 22:50 1302Java是如何管理内存 为了判断Java中是否有内 ... -
Transform XML into HTML using XSLT
2009-08-20 12:14 1846[howto.xml] <?xml versio ... -
eclipse 无法启动 JVM terminated. Exit code=-1
2009-08-09 13:52 2483eclipse 无法启动 JVM terminated. ... -
SDO ,WorkMananger,CommonJ overview
2009-07-06 10:51 1314Service Data Objects (SDO) -- P ... -
JAVA中多种计时器的比较与分析
2009-07-06 10:34 24106介绍 计时器可以提供运行基于时间的工作任务的功能,在计时器的管 ... -
Apache common io overview
2009-07-05 20:28 3890Apache 里面包含了太多有用的项目,值得我们仔细研究。恰当 ... -
Hashtable和HashMap的区别 Vector、ArrayList和List的异同(笔记)
2009-07-04 08:10 1917Hashtable和HashMap的区别:1.Hashtabl ... -
Java: System Properties
2009-05-25 11:10 2062From System Properties you ca ... -
SSL证书转换
2009-05-18 17:33 8532PKCS 全称是 Public-Key Cryptogra ... -
Keystores and Truststores
2009-05-18 14:39 2673Keystores and Truststores ... -
google app engine 是什么?
2009-04-08 18:50 3256Google是个真正能不断的 ... -
如何输入版权符号 copyright
2009-04-08 13:21 12327Unicode Character 'COPYRIGH ... -
深入浅出URL编码
2009-04-05 13:31 1133版权声明:如有转载请 ... -
Java IO一览
2009-04-04 12:23 1690对于我们常用的GBK中,英文是占用1个字节,中文是2个 对于 ... -
字节流与字符流的区别
2009-04-04 12:13 15118最近在项目中遇到一个encoding的问题,记录一下。 ... -
深入了解Unicode
2009-04-02 00:31 1727Unicode (统一码 、万国 ...
相关推荐
Preferences sysPrefs = Preferences.systemRoot(); // 设置键值 sysPrefs.put("exampleKey", "exampleValue"); // 读取键值 String value = sysPrefs.get("exampleKey", "defaultValue"); System.out....
JDKTM 6 Documentation Legal Notices API, Language, and ...org.omg.stub.java.rmi org.w3c.dom org.w3c.dom.bootstrap org.w3c.dom.events org.w3c.dom.ls org.xml.sax org.xml.sax.ext org.xml.sax.helpers
答案是肯定的,从 JDK 1.4 起,Java 提供了 java.util.prefs 包,其中有一个 Preferences 类,可以帮助我们实现对系统注册表进行操作。Preferences 类在不同的平台中有不同的实现方式。在 Windows 平台中,...
对于Java程序来说,虽然不直接访问系统的注册表,但可以通过Java平台提供的`java.util.prefs.Preferences`类来模拟这一功能。这种方式不仅限于Windows系统,也适用于其他操作系统,如Linux或Mac OS。 #### 三、...
- `java.util.prefs.Preferences` 是Java内置API,用于存储应用的首选项。 - 通过`Preferences`,可以将程序相关的配置信息保存到Windows注册表中。 **步骤**: 1. **创建Preference对象**:通过调用`Preferences....
例如,可以通过调用`Preferences.systemRoot().node("Software\\JavaSoft\\Prefs")`获取到`HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs`节点,然后使用`put`和`get`方法进行数据的存取。 但是,需要注意的是,`...
Preferences API主要包括两个主要类:`java.util.prefs.Preferences.systemNodeForPackage()`和`java.util.prefs.Preferences.userNodeForPackage()`. `systemNodeForPackage()`返回的是系统级别的偏好设置,通常...
Java 操作注册表主要涉及到 `java.util.prefs` 包中的 `Preferences` 类,这是一个用于存储用户和系统首选项的接口。从 JDK 1.4 开始,Java 提供了这个包来支持跨平台的首选项存储,允许开发者在不依赖特定操作系统...
在Java中,通过`java.util.prefs.Preferences`类可以实现与注册表的交互,包括读取、写入和删除键值等操作。 ### 代码示例解析 在给定的部分内容中,我们看到了一个名为`PrefsDemo`的Java类,该类展示了如何使用...
本文介绍了三种使用Java修改Windows注册表的方法:利用`java.util.prefs.Preferences`、使用“regedit /s”命令导入注册表文件以及使用第三方库GDAPI。每种方法都各有优势和局限性,开发者应根据实际需求选择最合适...
prefs = Preferences.userRoot().node(this.getClass().getName()); String ID1 = "Test1"; String ID2 = "Test2"; String ID3 = "Test3"; // 获取并打印偏好值 System.out.println(prefs.getBoolean(ID1, ...
在JDK1.4中,Java平台引入了`java.util.prefs`包,这是通过JSR10(Java Specification Request)规范添加的新功能。这个包提供了一个跨平台的API,允许开发人员在不同的操作系统上操作用户的首选项数据和配置信息。...
Java提供了多种持久化存储方案,如`java.util.prefs.Preferences`用于轻量级配置存储,或者使用数据库(如SQLite)进行更复杂的数据管理。 10. **调试和日志**: 开发过程中,调试和日志记录是非常重要的。Java提供...
此外,还可以使用第三方库如Apache Commons Configuration或Java 8引入的`java.util.prefs.Preferences` API来提供更高级的配置管理功能,如支持XML配置、默认值、监听属性变化等。 总结,Java中的`java.util....
Java Preferences User Interface(JPUI)是一个开源项目,专注于提供一个基于Java/Swing的图形用户界面,使得用户可以方便地浏览和编辑使用Java 1.4.x版本中的`java.util.prefs`包创建的Java首选项。Java首选项系统...
Java提供了多种本地存储选项,如`java.util.prefs.Preferences`系统,或者使用`java.io.File`或`java.nio.file`包来读写文件。 总的来说,实现Java自动登录功能需要理解HTTP协议、Cookie和Session机制,掌握网络...
10. **持久化状态**:如果需要保存用户自定义的视图设置或最近访问的路径,可以使用`java.util.prefs.Preferences`来存储这些信息。 11. **权限管理**:理解并应用Java的权限模型,确保用户只能执行他们有权限的...
Preferences prefs = Preferences.systemRoot().node("/javaplayer"); prefs.put("version", "1.3"); prefs.put("initial", "ini.mp3"); prefs.put("creator", "***"); // 可以选择性地调用flush()和sync()方法...
import java.util.prefs.Preferences; public class SWLicenseManager { public SWLicenseManager() { } public LicenseContent verifyLicenseKey(LicenseParam parameter) { LicenseManager manager = new ...