简体   繁体   English

在Android模拟器中创建文件夹

[英]creating folder in android emulator

I am developing an android application. 我正在开发一个android应用程序。 I need to create a folder in the internal memory, but when I try to create the folder I get the error below. 我需要在内部存储器中创建一个文件夹,但是当我尝试创建该文件夹时,出现以下错误。 I am running in an emulator. 我正在模拟器中运行。

 mkdir failed for /mnt/New Folder , read only file system

I have tried many paths, but still the error persists. 我尝试了许多路径,但错误仍然存​​在。 The only folder that I am able to create is called "cache", but I cannot browse it by my file chooser activity. 我能够创建的唯一文件夹称为“缓存”,但是我无法通过文件选择器活动来浏览它。 Any idea where is the suitable place to create folders without any permissions? 知道没有权限创建文件夹的合适位置在哪里吗?

You can achieve it by this from a Context object (like Activity). 您可以通过Context对象(例如Activity)来实现。

File files_folder = getFilesDir(); 
File files_child = new File(files_folder, "files_child"); 
files_child.mkdirs(); 
File created_folder = getDir("custom", MODE_PRIVATE); 
File f1_child = new File(created_folder, "custom_child"); 
f1_child.mkdirs(); 

The function 功能

getFilesDir()

will get the folder data/data/yourpackagename/files in internal memory. 将在内部存储器中获取文件夹数据/数据/包名称/文件。 And the function 和功能

getDir("custom", MODE_PRIVATE)

will create a folder name app_custom in your app internal folder. 将在您的应用内部文件夹中创建一个名为app_custom的文件夹。

Answered by Minhtdh 回答Minhtdh

I guess what you call internal memory is atualy the external memory (which can be open by 我猜你所说的内部存储器通常是外部存储器(可以通过以下方式打开

file chooser activity, the real internal memory only can be open if you have rooted) 文件选择器活动,只有在拥有root用户的情况下,才能打开真正的内部存储器)

If that true, you should chek those belows: - first, you will need the write storeage permission in Manisfest 如果是这样,则应检查以下内容:-首先,您需要在Manisfest中具有写存储权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> - then you should use ` <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> -那么您应该使用`

String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/yourfoldername" 字符串路径= Environment.getExternalStorageDirectory()。getAbsolutePath()+“ /您的文件夹名称”

` than `比

mnt/yourfoldername MNT / yourfoldername

  • at last you should use mkdirs to create folder than mkdir 最后,您应该使用mkdirsmkdir创建文件夹

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM