查找“应用程序数据"的目录在 linux 和 Macintosh 上 [英] Find directory for "application data" on linux and macintosh

查看:18
本文介绍了查找“应用程序数据"的目录在 linux 和 Macintosh 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于 LWJGL 的游戏引擎,要运行它,我需要将所需的本机库放置到用户的计算机上.在 Windows 上,我通过以下方式找到应用程序数据目录:

I have a game engine based on LWJGL, and to run it I need to place the required native libraries onto the user's computer. On Windows, I do so by finding the Application Data directory via:

System.getenv("APPDATA");

并且一切都可以轻松而良好地运行.我创建了一个 File 对象,必要时调用 mkDir,如果文件不在机器上,则写入文件.

and everything works easily and nicely. I create a File object, call mkDir if necessary, and write the files if they are not already on the machine.

(注意:创建的目录不应该是临时文件,因为我想保存提取的文件以备将来运行.此外,创建此目录为保存的游戏和其他此类提供了一个简单易用的文件夹数据.)

(Note: the created directory should not be a temporary file, as I would like to save the extracted files for future runs. Additionally, creating this directory gives a simple and easy-to-use folder for saved games and other such data.)

但是,如果计算机是 Macintosh 或 Linux,我想做类似的事情,但我不太熟悉如何使用这两个系统进行操作,而且我也不太适合进行测试.我目前找到目标目录的方法是这样的:

However, I'd like to do something similar if the computer is Macintosh or Linux, but I'm not as familiar with how to do so with those two systems, and I'm not really in a good testing position. My current method to find the target directory is this:

private static String defaultDirectory()
{
    String OS = System.getProperty("os.name").toUpperCase();
    if (OS.contains("WIN"))
        return System.getenv("APPDATA");
    else if (OS.contains("MAC"))
        return System.getProperty("user.home") + "/Library/Application "
                + "Support";
    else if (OS.contains("NUX"))
        return System.getProperty("user.home");
    return System.getProperty("user.dir");
}

那么,这是正确的做法吗?我正在尝试访问 Mac 上的应用程序支持(我了解到这相当于 Windows 上的 AppData 文件夹)并且我正在尝试在 Linux 上使用类似的文件夹,但我不确定user.home"找到正确的.

So, is this the right way to do this? I'm trying to reach the Application Support on Mac (I've learned this is the equivalent of the AppData folder on windows) and I'm trying to use a similar folder on Linux, but I'm not sure if "user.home" finds the correct one.

推荐答案

这应该有效.只是一件事:在 linux 上,最好将设置保存在用户目录的隐藏文件夹中.因此,对于 linux,请将您的文件夹放在 $HOME/.config 下,或者以 . 开头以使其隐藏.

this should work. just one thing: on linux it is preferred to keep settings in a hidden folder in user directory. So for linux, either put your folder under $HOME/.config, or start the name with the . to make it hidden.

这篇关于查找“应用程序数据"的目录在 linux 和 Macintosh 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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