问题描述
我正在尝试在Java应用程序上遵循XDG目录规范.我已经将它用于应用程序数据:
I'm trying to follow XDG directory specification on my Java application. I have already used it for application data:
protected String getDefaultDataDir() {
String rootPath = System.getenv("XDG_DATA_HOME");
if(rootPath == null) {
rootPath = System.getProperty("user.home")+S+".local"+S+"share";
}
return rootPath+S+Pinocchio.PLATFORMNAME;
}
(S是一个包含 System.getProperty("file.separator"))
我现在想将文档存储在用户文档的文件夹中.但是我没有名为XDG_DOCUMENTS_DIR的环境变量.我有具有该XDG配置的".config/user-dirs.dirs"文件和直接返回该路径的"xdg-user-dir DOCUMENTS".
I want now to store documents on the user documents' folder. But I don't have an environment variable named XDG_DOCUMENTS_DIR. I have the ".config/user-dirs.dirs" file that have that XDG configuration, and the "xdg-user-dir DOCUMENTS" which directly returns that path.
更糟糕的是,默认的documents目录取决于用户的语言环境.
Making things worse, the default documents directory depends on the user locale.
哪种方法是在Java应用程序上使用已配置的Documents目录的最佳方法?
Which is the best way to use the configured Documents directory on a java application?
推荐答案
在Gnome上有java-gnome支持库,它在进行本机调用以更好地与gnome集成.它可以通过调用 Glib.getUserSpecialDir
.我自己还没有尝试过,如果您打算在程序中使用更多台式机集成功能,可能值得一试.
On Gnome there is java-gnome support library, it is doing native calls for better integration with gnome. It can get path of user dirs via calls to Glib.getUserSpecialDir
. Haven't tried this one myself, might be worth a try if you are planning to use more desktop-integrated features in your program.
这篇关于在Java应用程序上使用XDG目录规范的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!