有没有办法在Windows下使用java.util.Preferences,而不使用注册
我想使用
java.util.Preferences API,但我不希望我的程序尝试读取或写入
Windows注册表.我该怎么办?
我相信你已经阅读了
read/write to Windows Registry using Java,然后在使用java.util.Preferences API时想要比注册表另一个后端
您可以扩展
new 那比IMO更好,而不是使用另一个API. 例如,搜索延伸 >您可以使用由XML文件支持的首选商店:
import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.prefs.AbstractPreferences; import java.util.prefs.BackingStoreException; /** * Own implementation of the Java preferences API,that does not use * a "OS backing store" but relies on importing and exporting the * preferences via xml files. * Also,If a preference is got,but was not in the tree,it is entered. */ public class MyPreferences extends AbstractPreferences { private Map<String,String> prefs = new HashMap<String,String>(); private Map<String,AbstractPreferences> children = new HashMap<String,AbstractPreferences>(); public MyPreferences(MyPreferences parent,String name) { super(parent,name); } /** * @see java.util.prefs.AbstractPreferences#putSpi(java.lang.String,java.lang.String) */ protected void putSpi(String key,String value) { prefs.put(key,value); } >或者您可以将这些首选项存储在LDAP中:
import java.util.prefs.AbstractPreferences; import java.util.prefs.BackingStoreException; import javax.naming.NamingException; import javax.naming.directory.Attributes; import de.tarent.ldap.LDAPException; import de.tarent.ldap.LDAPManager; /** * @author kirchner * * Preferences im LDAP */ public class LDAPSystemPreferences extends AbstractPreferences { LDAPManager ldm = null; Properties properties = new Properties(); //Map für key/value der Preferences Map cache = new HashMap(); //Map für timestamp der Preferences Map timestamp = new HashMap(); private Boolean deleted = Boolean.FALSE; >或者你可以使用一个简单的属性文件: com.adito.boot.PropertyPreferences: import java.util.prefs.AbstractPreferences; import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * A simple implementation for the preferences API. That stores preferences * in propery files. We do not have to worry about sharing the preferencese * with other JVM instance so there is no need for any kind of synchronising * or locking. */ public class PropertyPreferences extends AbstractPreferences { (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 解决运行前出现的地址错误问题-emp
- 在Windows中转义curl命令
- windows-xp – GnuPG:“解密失败:秘密密钥不可用”错误从
- windows-server-2012 – Windows Server 2012默认RAM分配策
- Windows等效于Unix的pdfinfo
- 如何在Cygwin Windows中的HTTPS URL上运行wget时修复证书错
- 模拟和Win32 API调用
- windows-server-2008-r2 – Apache 2.4是不可杀死的,无法在
- windows – 我可以一次打开多少个TCP套接字?
- windows-server-2008 – 备份Exchange 2010
- Windows Server 2016-安装AD域服务注意事项
- windows-server-2008-r2 – IIS7 Windows身份验证
- winapi – Win8 – Windows.UI.Xaml.dll中的未处
- Microsoft SQL Server(MSSQL)可更新视图,具有多个
- 将Windows上的Oracle迁移至Linux
- 域名系统 – Windows 7:“本地主机名称解析在DN
- 是否有可用于Windows的Unicode字体,与Arial Unic
- windows-phone-7 – 在phone7中打开一个项目文件
- QT 使用QSetting读取配置文件中的中文乱码解决方
- windows – 如何删除本地管理员权限?