Permission to write on SD card android

前端 未结 4 679
逝去的感伤
逝去的感伤 2020-12-30 16:49

I have a problem writing to the SD card, here is the code: (Sorry about the layout of the code, just copy pased it )

public class SaveAndReadManager {

 priv         


        
4条回答
  •  醉话见心
    2020-12-30 17:08

    Which result are you seeing retunred from writeToFile? "file not written" or "file cant write"?

    When I ran your code it dropped into the catch IOException block with the result of "file not written". The reason for this was that fos was defined incorrectly:

    fos = new FileOutputStream( saveFileName );
    

    should be:

    fos = new FileOutputStream( root + "/" saveFileName );
    

    After I changed this line, I got the result "File written" returned from writeToFile.

提交回复
热议问题