Saving file to phone instead of SD card

前端 未结 4 1945
孤街浪徒
孤街浪徒 2021-01-20 14:45

In my app I save an XML file to the user\'s SD card by doing File newxmlfile = new File(Environment.getExternalStorageDirectory() + \"/Message.xml\");

B

相关标签:
4条回答
  • 2021-01-20 15:17

    You can use openFileOutput to get an access to the internal storage. For more info, you should read the documentation on internal storage.

    0 讨论(0)
  • 2021-01-20 15:20

    First you should check if External Storage (SD card) is available and ready to write to by checking getExternalStorageState(). Read more here: http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

    Then if SD card not available you can write to internal storage. Read more here for example on how to write and read: http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

    0 讨论(0)
  • 2021-01-20 15:27

    Try andriods Data-Storage.

    Hope this helps.

    0 讨论(0)
  • 2021-01-20 15:44

    Got it by changing

    Environment.getExternalStorageDirectory() + "/Message.xml"
    

    into

    Environment.getDataDirectory() + "/data/com.companyname.appname/files/Message.xml"
    
    0 讨论(0)
提交回复
热议问题