简体   繁体   English

在运行时从内部存储读取/写入一些文件

[英]read/write some files from internal storage at runtime

I am developing a program that need read/write some files from sdcard or internal storage at runtime. 我正在开发一个程序,需要在运行时从sdcard或内部存储读取/写入一些文件。 When I mount the sdcard in my phone it run correctly but if i unmount sdcard my application raises some error. 当我在手机中安装sdcard时,它可以正常运行,但是如果我卸载sdcard,我的应用程序将引发一些错误。 What I have to do for phones that have not card slot like Htc one x or phones that have not any sdcard inserted? 对于没有Htc one x卡插槽的手机或没有插入sdcard的手机,我该怎么办? how i can write on those phones storage? 我如何在那些手机存储上写东西? I don't want write this file into /data/data/my.app.package folder. 我不想将此文件写入/data/data/my.app.package文件夹。 I want write somewhere that files can be read from another apps. 我想写一个可以从其他应用程序读取文件的地方。 first I check storage status with this code and if sdcard be inserted and writable i have not any problem. 首先,我用此代码检查存储状态,如果sdcard可插入且可写,我没有任何问题。 but if sdcard does not exists i realy don't know what i have to do. 但是如果sdcard不存在,我真的不知道该怎么办。

string _location;  
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
          _location=Environment.getExternalStorageDirectory()+"/myfolder/";
          Toast.makeText(context, _location, 1000).show();
      }
      else
      {
          _location="/myfolder/"
          Toast.makeText(context, Environment.getExternalStorageDirectory().toString(), 1000).show();

      }

      mysync mys=new mysync(); // Asynctasc that writes some file on _location path
      mys.execute(_location);

i am so confused and undortunately i haven't any phone with big internal storage. 我很困惑,很不幸,我没有任何带有大内部存储空间的手机。 please help me. 请帮我。

I am developing a program that need read/write some files from sdcard or internal storage at runtime. 我正在开发一个程序,需要在运行时从sdcard或内部存储读取/写入一些文件。

Here, and in your question title, you say you want to write to internal storage. 在这里,在问题标题中,您说您写入内部存储。 Later, you say that you do not want to write to internal storage. 稍后,您说您不想写入内部存储。

Which is it? 哪有

What I have to do for phones that have not card slot like Htc one x or phones that have not any sdcard inserted? 对于没有Htc one x卡插槽的手机或没有插入sdcard的手机,我该怎么办?

External storage != "sdcard". 外部存储!=“ sdcard”。 External storage can be whatever the device manufacturer wants, so long as it meets the terms of the Compatibility Definition Document. 外部存储可以是设备制造商想要的任何东西,只要它符合兼容性定义文档的条款即可。 Hence, external storage can be removable (eg, SD card) or not (eg,. dedicated portion of on-board flash). 因此,外部存储设备可以是可移动的(例如,SD卡),也可以不是(例如,板载闪存的专用部分)。 And, on Android 3.0+, external storage is merely a special subdirectory on the same partition that contains internal storage. 而且,在Android 3.0+上,外部存储只是包含内部存储的同一分区上的一个特殊子目录。

You only care about whether external storage is presently available or not. 您只关心当前是否有外部存储可用。 It should be available pretty much all of the time on Android 3.0+ devices. 在Android 3.0及更高版本的设备上,它几乎应该一直可用。 It will be unavailable on Android 1.x and 2.x devices if the device is plugged into a host computer and the host computer has mounted the device's external storage (eg, as a drive letter on Windows). 如果将设备插入主机并且主机已安装设备的外部存储(例如,在Windows上作为驱动器号),则该功能在Android 1.x和2.x设备上将不可用。

if sdcard does not exists i realy don't know what i have to do. 如果SD卡不存在,我真的不知道该怎么办。

You ask the user to please unmount their device from their host computer. 您要求用户从主机上卸载设备。 Or, you decide to write to internal storage in those cases. 或者,在这种情况下,您决定写入内部存储。

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

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