Read the file or folder instance under the Android root directory

In recent days, I have been busy in various senses, busy with exams and curriculum design. I have outsourced projects on hand. On the other hand, I have to engage in school projects. My own things are still in the document stage. It really makes people want to die!!

For nearly half a month, c# this aspect of coding has been relatively large. Android and java have been completely shelved here, so I took the time to write a small example.

This example is very small, which is to read the folder or file in the Android root directory as a hot one.

First, we need to obtain the names of all files or folders under the folder through the file. Listfiles() method. The path of the folder here is "/", that is, the root directory. Then we get their relative paths one by one through getpath().

The running results of the example are as follows:

Of course, we need to add permissions to the root file:

Because the example is too small and the length of the whole article is not long, all file operations are specially listed at the back of the article for your reference:

1、 SDK operation

1. Determine whether the SD card is inserted

This is very useful in my previous work, because it involves reading the SDK. Naturally, you need to judge whether the SDK is inserted first.

2. Get SD card root directory:

2、 File operation in private directory:

1. Get private root:

2. Folder or folder operation:

(1) Get folder and file paths

a. Gets the absolute and relative paths of a file or folder. difference

b. Gets the parent directory of the file or folder

c. Get the name of the file or folder:

(2) Create a file or folder

(3) Determine whether it is a file or folder

(4) Lists all files and folder names under the folder

(5) Modify folder and file names

(6) Delete folder or file

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>