How do you write to a folder on an SD card in Android?

后端 未结 4 1388
深忆病人
深忆病人 2020-11-22 07:50

I am using the following code to download a file from my server then write it to the root directory of the SD card, it all works fine:

package com.downloader;         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 08:48

    File sdCard = Environment.getExternalStorageDirectory();
    File dir = new File (sdCard.getAbsolutePath() + "/dir1/dir2");
    dir.mkdirs();
    File file = new File(dir, "filename");
    
    FileOutputStream f = new FileOutputStream(file);
    ...
    

提交回复
热议问题