Reputation: 875
I want to be able to copy a file from within my apk to the sd-card and was just wondering if it was possible and how i would go about it as im struggling to find and infomation and the android chat rooms are all locked! Thanks in advance :)
Edit: I would like to push the file to the internal storage (prefrably /system/ but i can move it from the internal storage to there using terminal commands if needed)
Upvotes: 0
Views: 129
Reputation: 4214
This is about how to push into internal storage http://developer.android.com/guide/topics/data/data-storage.html#filesInternal
Upvotes: 0
Reputation: 73365
Put your file inside assets
folder on your project, e.g. file.txt.
Get input stream to read the file:
InputStream is = getAssets().open("file.txt");
Copy the contents:
FileOutputStream os = new FileOutputStream(new File(Environment.getExternalStorageDirectory(), "file.txt"))
byte[] buf = new byte[4096]
while (true) {
int len = is.read(buf);
if (len < 0) break;
os.write(buf, 0, len);
}
os.close();
is.close();
Upvotes: 4