在内部和外部SdCard上存储文件

在内部和外部SdCard上存储文件

本文介绍了在内部和外部SdCard上存储文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件保存在内部和外部SD卡上..基本上,我想给用户一个选择,以将文件保存在内部或外部SD卡上这就是我在内部SD卡中创建文件的方式

I am trying to save a file on both internal and external sd card .. basically I want to give user an option to save file on internal or external cardsThis is how I am creating file in Internal SD card

File file = new File(Environment.getExternalStorageDirectory()
            + "/Tnt_input/register.html");

但是如何在External SD card ...中创建此文件?

but how to create this file in External SD card...?

我可以在DDMS中看到两个存储空间

I can see two storage in DDMS

1) sdCard0

2) extSdCard

通过使用上述代码在sdCard0

推荐答案

最后找到了一个可行的解决方案,但没有推荐,要使用外部编码卡,我使用了/storage/extSdCard/StorageTest/input之类的硬编码路径,但该路径取决于设备,上述路径适用于Samsung Galaxy note系列,但对于xperia Z,其路径为/storage/removable/sdcard1.这个解决方案对我有用,因为我的客户使用特定的设备.但是像这样,您不能创建在每个设备上都可以使用的全局方法,因此这是对我有用的代码

Finally found a working solution , but its not recomended, to get to external sd card i used hard coded path , like /storage/extSdCard/StorageTest/input but this path depends upon device , the above path works in Samsung Galaxy note series but for xperia Z its /storage/removable/sdcard1. This solution worked for me because my client use a specific device.But like this you cant create a global method which works on every device, so here is the code which worked for me

String galaxy_note = "/storage/extSdCard";
File file = new File(galaxy_note
    +"/StorageTest/input");

您还可以通过使用以下命令检查设备中是否安装了可移动sd卡,或者没有

you can also check if there is a removable sd card installed in device or no by using

Environment.isExternalStorageRemovable();

这篇关于在内部和外部SdCard上存储文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 17:45