Java 如何访问android中的特定内部存储目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34881655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access a particular internal storage directory in android?
提问by Adi
I am trying to learn android programming. As a beginning, I am trying to understand the internal file system & accessing them. Any help is highly appreciated. Following are my challenges:
我正在尝试学习android编程。首先,我试图了解内部文件系统并访问它们。任何帮助都受到高度赞赏。以下是我的挑战:
- How to create a 'TEST' folder through the android emulator/Android device monitor? I need to create the folder where the alarms, download, DCIM folder are present.
What is the absolute directory path to the 'TEST' folder created? Is it possible to access the TEST folder using the code below:
List<File> list = Environment.getDataDirectory()+"/TEST".listFiles();
Does any permission to be mentioned in the manifest for read/write to internal storage?
- 如何通过 android 模拟器/Android 设备监视器创建“TEST”文件夹?我需要创建存在警报、下载、DCIM 文件夹的文件夹。
创建的“TEST”文件夹的绝对目录路径是什么?是否可以使用以下代码访问 TEST 文件夹:
List<File> list = Environment.getDataDirectory()+"/TEST".listFiles();
清单中是否有任何权限可用于读取/写入内部存储?
PS: I use Android Studio.
PS:我使用Android Studio。
采纳答案by denixtry
You would want something along the lines of
你会想要一些类似的东西
File TEST = new File(Environment.getExternalStorageDirectory(), "TEST");
TEST.mkdir(); // make directory may want to check return value
String path = TEST.getAbsolutePath(); // get absolute path
and permissions
和权限
<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
</manifest>
Further reference
进一步参考
回答by ayush srivastava
File file = new File("storage/emulated/0","yourfoldername/");
File file = new File("storage/emulated/0","yourfoldername/");
This worked for me if this doesn't help, then in use
如果这没有帮助,这对我有用,然后在使用
File(Environment.getobbdir(),"yourfoldername");
File(Environment.getobbdir(),"yourfoldername");