读取Android中特定文件夹内的内部文件 [英] Read internal files inside a particular folder in Android
问题描述
当然,这不是一个很难回答的问题,但是我在实现此问题时遇到了一些麻烦.我的问题是:我需要读取(或列出)Android内部存储器中特定文件夹(例如,内部存储器根目录中的"myFolder")内的文件.当然可以,但是该怎么做呢?预先感谢!
Surely, this ins't a very hard question to be answered, but I'm having some trouble to implement this. My issue is: I need to read (or list) the files inside of a particular folder (say "myFolder", located in internal storage root) in Android's internal storage. Sure, it is possible, but how to do this? Thanks in advance!
推荐答案
要读取设备中的文件,您可以执行以下操作:
To read the files inside your device you would do something like this:
// gets the files in the directory
File fileDirectory = new File(Environment.getDataDirectory()+"/YourDirectory/");
// lists all the files into an array
File[] dirFiles = fileDirectory.listFiles();
if (dirFiles.length != 0) {
// loops through the array of files, outputing the name to console
for (int ii = 0; ii < dirFiles.length; ii++) {
String fileOutput = dirFiles[ii].toString();
System.out.println(fileOutput);
}
}
如果要从SD卡中取出文件,只需将getDataDirectory
更改为getExternalStorageDirectory
.
If you wanted to get the files off an SD card, you would simply change getDataDirectory
to getExternalStorageDirectory
.
这篇关于读取Android中特定文件夹内的内部文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!