Java 具有相对路径的Android文件类mkdirs不';t像绝对路径一样工作

Java 具有相对路径的Android文件类mkdirs不';t像绝对路径一样工作,java,android,Java,Android,我想在android中使用相对路径创建目录。但它无法使用相对路径。我只有走上绝对的道路才能获得成功 示例代码:(相对路径)(不适用于目录,适用于文件) 示例代码:(绝对路径)(在文件和文件夹中工作) 请注意,我在android问题跟踪器中发现了发布的问题。请查看下面的链接。你为什么要摆弄user.dir? System.setProperty("user.dir", getFilesDir().getAbsolutePath()); File logDirectory = new File("

我想在android中使用相对路径创建目录。但它无法使用相对路径。我只有走上绝对的道路才能获得成功

示例代码:(相对路径)(不适用于目录,适用于文件)

示例代码:(绝对路径)(在文件和文件夹中工作)


请注意,我在android问题跟踪器中发现了发布的问题。请查看下面的链接。你为什么要摆弄
user.dir
System.setProperty("user.dir", getFilesDir().getAbsolutePath());

File logDirectory = new File("sample");
// Success will be always false here.
boolean success = logDirectory.mkdirs();

// But I got success in file creation with relative path.
FileOutputStream fos = new FileOutputStream("sample.txt");
fos.write(1);
fos.close();
System.setProperty("user.dir", getFilesDir().getAbsolutePath());

File logDirectory = new File(System.getProperty("user.dir") + "/sample");
// Success will be always true here.
boolean success = logDirectory.mkdirs();
FileOutputStream fos = new FileOutputStream("sample.txt");
fos.write(1);
fos.close();