This is my first Android application I'm making, so I'm a bit lost on what the terms are for everything.
I'm trying to copy a file I have in my /raw/ directory to the root of my SD card.
Currently, my (used Stackoverflow, didn't write this fully myself) code looks like this:
btnWriteSDFile.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
try {
File myFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "fileName.docx");
myFile.createNewFile();
Toast.makeText(v.getContext(),"Wrote line", Toast.LENGTH_SHORT).show();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter =new OutputStreamWriter(fOut);
myOutWriter.append("testFile");
myOutWriter.close();
fOut.close();
Toast.makeText(v.getContext(),"Done writing SD 'mysdfile.txt'", Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Toast.makeText(v.getContext(), e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
});
I get the error: "open failed; EACCES (Permission Denied)".
My Manifest looks like this:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permisson.READ_EXTERNAL_STORAGE" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Clarification to avoid duplication: Besides the fact that I get this error: how can I write a /raw/file.docx file to my SD card root?