简体   繁体   English

在sdcard0和sdcard1 android中保存文件

[英]Saving a file in sdcard0 and sdcard1 android

I want to give an option to the user to store a video file in sdcard0(internal memory) or sdcard1. 我想给用户一个选项,将视频文件存储在sdcard0(内部存储器)或sdcard1中。 How can I do that. 我怎样才能做到这一点。 Environment.getExternalStorageDirectory() and Environment.getExternalPublicStorageDirectory() will save the file in sdcard1. Environment.getExternalStorageDirectory()和Environment.getExternalPublicStorageDirectory()将文件保存在sdcard1中。 How can I save a file in sdcard0? 如何在sdcard0中保存文件?

Try this code 试试这个代码

  String sdcard_path = Environment.getExternalStorageDirectory().getPath();
                    Log.d("Path ------ ", " " + sdcard_path);
                    // create a File object for the parent directory
                    File PapersDiractory = new File(sdcard_path + "/Exam Papers/");
                    // have the object build the directory structure, if needed.
                    PapersDiractory.mkdirs();
                    // create a File object for the output file
                    File outputFile = new File(PapersDiractory, "five-point-someone-chetan-bhagat_ebook.pdf");
   ContextWrapper contextWrapper = new ContextWrapper(
                getApplicationContext());
        File directory = contextWrapper.getDir(filepath,Context.MODE_PRIVATE);
        myInternalFile = new File(directory, filename);
try {
            FileOutputStream fos = new FileOutputStream(myInternalFile); // save
            fos.write(myInputText.getText().toString().getBytes());
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        myInputText.setText("");
        responseText.setText("Saved to Internal Storage.(StorageFile.txt)");

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

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