Android 获取应用程序启动路径

Android Get Application Start Up Path

在 C# 中,有 Application.StartUpPath 或 Application.AppDataPath 全局方法来获取存储应用程序设置的路径。

我试过了static String fName = System.getProperty("user.dir") + "SatCli.conf";

"/SatCli.conf" - 结果是 fName

那我打电话给

 BufferedOutputStream oustream = new BufferedOutputStream(new
 FileOutputStream(fName, false));

我遇到了常见异常

"/SatCli.conf: open failed: EROFS (Read-only file system)"

好吧,我一直在 Unix 下编写应用程序,我知道文件名可能指的是内部存储器..换句话说就是系统文件系统的根部分。

也可能不是..可能指的是应用程序文件夹?

无论如何,我想得到的是正确的方法来获得正确的文件夹来存储设置数据。 另外,重要的是,在构建任何上下文之前,当初始化静态字段时,我需要它。

感谢您的任何相关提示和帮助。

what I would like to get is the correct method to get the right folder to store the settings data.

对于任意文件,在 Context 上调用 getFilesDir()(例如,Activity)。这为您提供了一个 File 对象,表示您的应用程序可以在其中读取和写入的私有目录。

FWIW,Android 存储您从用户那里收集的设置的标准方式是 SharedPreferences,因此您可以利用 PreferenceFragment 的 UI .