简体   繁体   English

Android中的SD卡存储

[英]SD card storage in android

Please excuse me if this was already explained. 如果已经说明了,请原谅。

I am using file path as Environment.getExternalStorageDirectory()+"/myfolder/myfile.img for storing file with manifest permissions .It is working fine for me . 我正在使用文件路径作为Environment.getExternalStorageDirectory()+"/myfolder/myfile.img来存储具有清单权限的文件。 Environment.getExternalStorageDirectory()+"/myfolder/myfile.img我来说很好。

I have some queries regarding this line of code. 我对这行代码有一些疑问。

  1. I noticed that this creates a folder in internal memory, what about if there is no enough space in internal memory? 我注意到这会在内部存储器中创建一个文件夹,如果内部存储器中没有足够的空间该怎么办?

  2. And what about if there is enough memory in external SD card? 如果外部SD卡中有足够的内存该怎么办?

  3. Will it automatically create folder in external memory card? 会自动在外部存储卡中创建文件夹吗?

Thanks in advance. 提前致谢。

From here: http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory() 从这里: http : //developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()

Return the primary external storage directory. 返回主外部存储目录。 This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened. 如果用户已将其安装在计算机上,已从设备中删除或发生了其他问题,则该目录当前可能无法访问。 You can determine its current state with getExternalStorageState(). 您可以使用getExternalStorageState()确定其当前状态。

Note: don't be confused by the word "external" here. 注意:请勿在此处与“外部”一词混淆。 This directory can better be thought as media/shared storage. 最好将此目录视为媒体/共享存储。 It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). 它是一个文件系统,可以保存相对大量的数据,并且可以在所有应用程序之间共享(不强制执行权限)。 Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer. 传统上,这是SD卡,但也可以将其实现为设备中的内置存储,该设备不同于受保护的内部存储,并且可以作为文件系统安装在计算机上。

1) you app crashes if you not catching exceptions 1)如果您未捕获异常,则应用程序崩溃
2) sames as 1. 2)与1相同。
3) no! 3)不!

Take a look at: http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory() 看看: http : //developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()

Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer. 传统上,这是SD卡,但也可以将其实现为设备中的内置存储,该设备不同于受保护的内部存储,并且可以作为文件系统安装在计算机上。

Depending on the device your file will be placed on the sdcard or the internal storage. 根据设备的不同,您的文件将放置在sdcard或内部存储中。

If no free space is available any IO action which writes data will fail. 如果没有可用空间,则任何写入数据的IO操作都会失败。

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

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