0
我想在我的android應用程序中集成文件瀏覽器功能。我能夠使用如下因素代碼片段來訪問手機的內置存儲器:無法讀取Android手機的內部和外部存儲文件
Path = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
但我無法找到讀取SD卡,以顯示從這些文件夾的文件的功能。請建議如何做到這一點。
我想在我的android應用程序中集成文件瀏覽器功能。我能夠使用如下因素代碼片段來訪問手機的內置存儲器:無法讀取Android手機的內部和外部存儲文件
Path = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
但我無法找到讀取SD卡,以顯示從這些文件夾的文件的功能。請建議如何做到這一點。
要使用外部存儲工作,你必須編輯您的清單文件:
<manifest ...>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
...
</manifest>
要從此目錄獲取文件的列表,你可以使用
File[] files = Environment.getExternalStorageDirectory().listFiles();
將在此之後,以彰顯你可以閱讀文件一行一行如下:
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"file.txt");
while ((line = br.readLine()) != null) {
//whatever you want
}
你使用的是哪個操作系統版本的android。上面的代碼是 – avinash
是讀取外部存儲器。和context.getFilesDir()。getAbsolutePath();此方法用於讀取內部存儲器 –
您無權在Android上對[可移動存儲](https://commonsware.com/blog/2014/04/09/storage-situation-removable-storage.html)進行任意訪問4.4+。 – CommonsWare