如何在Java中获取本地应用程序数据文件夹? [英] How to get local application data folder in Java?

查看:223
本文介绍了如何在Java中获取本地应用程序数据文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

获取本地应用程序数据目录路径的跨平台方式是什么?

我正在寻找一种方法来获取本地应用程序数据文件夹的位置,这是一个特殊的Windows文件夹,用Java编写。
不幸的是,以下内容仅适用于具有默认设置的英文版Windows XP:

I'm looking for a way to get the location of the local application data folder, which is a special Windows folder, in Java. Unfortunately, the following only works for English versions of Windows XP with default settings:

System.getProperty("user.home") + "\\Local Settings\\Application Data"

我是什么我想在.NET中有这样的东西:

What I'd like to have is something like this in .NET:

System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)

有没有办法在不必调用 SHGetSpecialFolderLocation

Is there a way to do it without having to call SHGetSpecialFolderLocation of the Windows Shell API?

推荐答案

从Windows 95开始,不推荐读取Shell文件夹注册表项。注册表项包含一条说明!不要使用此注册表项。请改用SHGetFolderPath或SHGetKnownFolderPath。我必须在Vista系统上找到这个方法,除了警告说明之外所有的密钥都丢失了。

Reading the "Shell Folders" registry key is deprecated starting from Windows 95. The registry key contains a note saying "!Do not use this registry key. Use the SHGetFolderPath or SHGetKnownFolderPath instead." I had to find this out the hard way on a Vista system where all the keys were missing except for the warning note.

这个相关的stackoverflow答案在Windows上使用JNA解决了这个问题,这是我目前正在使用的解决方案。

This related stackoverflow answer solves this problem on Windows using JNA, which is the solution I'm currently using.

这篇关于如何在Java中获取本地应用程序数据文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆