I have developed a android system application to copy file from /sdcard/download/test.txt to /cache/xyz/ location.
I am able to copy the file to /cache/ , but bot into /cache/xyz/ location ,
Getting below error :
java.io.FileNotFoundException: /cache/xyz/test.txt: open failed: EACCES (Permission denied)
File packageFile = new File(Environment.getDownloadCacheDirectory() + "/xyz/test.txt");
File downloadedFile = new File(Environment.getExternalStorageDirectory() + "/test.txt");
if (packageFile.exists()) {
Log.d(TAG, "TEST -> File in Cache Exists");
} else {
Log.d(TAG, "TEST -> File in Cache is Empty");
}
packageFile.canWrite();
if (downloadedFile.exists()) {
Log.d(TAG, "TEST -> packageFile in downloadedFile Exists");
FileChannel source = null;
FileChannel dest = null;
try {
source = (new FileInputStream(downloadedFile)).getChannel();
dest = (new FileOutputStream(packageFile)).getChannel();
count += dest.transferFrom(source, count, size-count);
catch (Exception e) {
Log.d(TAG, "TEST -> Failed to copy update file into internal storage: " + e);
}
} else {
Log.d(TAG, "TEST -> File DO NOT Exists");
}
Manifest :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />