I have tried this with and without the WRITE_INTERNAL_STORAGE permission.
There is no WRITE_INTERNAL_STORAGE
permission in Android.
How do I create this file for writing?
You don't, except perhaps on a rooted device, if your app is running with superuser privileges. You are trying to write to the root of internal storage, which apps do not have access to.
Please use the version of the FileOutputStream
constructor that takes a File
object. Create that File
object based off of some location that you can write to, such as:
getFilesDir()
(called on your Activity
or other Context
)
getExternalFilesDir()
(called on your Activity
or other Context
)
The latter will require WRITE_EXTERNAL_STORAGE
as a permission.
Is there an easier way than writing it to a file then reading from it again?
You can temporarily put it in a static data member.
because many people don't have SD card slots
"SD card slots" are irrelevant, by and large. 99% of Android device users will have external storage -- the exception will be 4+ year old devices where the user removed their SD card. Devices manufactured since mid-2010 have external storage as part of on-board flash, not as removable media.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…