使目录中的文件的内部存储文件、目录中

2023-09-06 01:16:14 作者:你是我此生最美的风景

我怎么做目录的内部存储?

How do i make directories in internal storage?

我尝试这样做:

File file = getFilesDir();

这让我进入到文件夹/data/data/com.mypackages/files /

this makes me goes to folder "/data/data/com.mypackages/files/"

然后我想打一个文件夹,再在该目录中,比方说,我想拍myfiles的文件夹,在那里,使其成为/data/data/com.mypackages/files/myfiles/。

Then i want to make a folder again in that directories, let's say i want to make "myfiles" folder in there so it becomes, "/data/data/com.mypackages/files/myfiles/".

谁能告诉我怎么样?

我也试过这样的:

File file = getDir("myfiles", MODE_PRIVATE);

有使该文件夹,但其用APP_创建的,所以目录变为/data/data/com.mypackages/app_myfiles。我不想说,因为我无法读取该文件夹,如果它在那里有APP_。

It makes the folder, but it was created with "app_", so the directories becomes "/data/data/com.mypackages/app_myfiles". I don't want that because i can't read the folder if it has "app_" in there.

推荐答案

解决的办法是在你的眼睛:D

The solution is under your eyes :D

m_applicationDir = new File(this.getFilesDir() + "");
m_picturesDir = new File(m_applicationDir + "/pictures");

通过这个code,我保存m_applicationDir包的目录(在你的情况下保存文件的目录)。 然后,只需创建一个子目录命名的图片。

With this code, i save in m_applicationDir the dir of the package (in your case the dir saved in file). Then simply create a sub-directory named pictures.

所以m_picturesDir指向:

So m_picturesDir points to:

/data/data/com.mypackages/files/pictures