I'm using this code for coping file from asset folder into sdcard but I got error and files copies with volume 3KB. I spend about 3 hour for solving problem but I could not! What's problem and solution
This code is for Copy
FileOperations.copyFromAsset(MainActivity.this,"database_tafsir_persian_azim","quran/data/database_tafsir_persian_azim");
public static void copyFromAsset(Context context,String src,String dst) throws IOException {
try{
AssetManager asset=context.getAssets();
InputStream in = asset.open(src);
OutputStream out = new FileOutputStream(new File(dst));//ERROR IS FROM THIS LINE
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
Log.i("Copying", "please wait...");
}
in.close();
out.close();
out.flush();
}catch(Exception e){
e.printStackTrace();
}
}
LOG CAT:
09-18 16:05:20.096: W/System.err(4219): java.io.FileNotFoundException: /quran/data/database_tafsir_persian_azim: open failed: ENOENT (No such file or directory)
09-18 16:05:20.165: D/TextLayoutCache(4219): Using debug level: 0 - Debug Enabled: 0
09-18 16:05:20.175: W/System.err(4219): at libcore.io.IoBridge.open(IoBridge.java:419)
09-18 16:05:20.175: W/System.err(4219): at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
09-18 16:05:20.175: W/System.err(4219): at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
09-18 16:05:20.175: W/System.err(4219): at ir.aiga.apps.quran.classes.FileOperations.copyFromAsset(FileOperations.java:112)
09-18 16:05:20.175: W/System.err(4219): at ir.aiga.apps.quran.MainActivity$ProgressHorizantol.doInBackground(MainActivity.java:732)
09-18 16:05:20.175: W/System.err(4219): at ir.aiga.apps.quran.MainActivity$ProgressHorizantol.doInBackground(MainActivity.java:1)
09-18 16:05:20.175: W/System.err(4219): at android.os.AsyncTask$2.call(AsyncTask.java:264)
09-18 16:05:20.175: W/System.err(4219): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-18 16:05:20.175: W/System.err(4219): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-18 16:05:20.186: W/System.err(4219): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
09-18 16:05:20.186: W/System.err(4219): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
09-18 16:05:20.186: W/System.err(4219): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
09-18 16:05:20.186: W/System.err(4219): at java.lang.Thread.run(Thread.java:856)
09-18 16:05:20.186: W/System.err(4219): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
09-18 16:05:20.186: W/System.err(4219): at libcore.io.Posix.open(Native Method)
09-18 16:05:20.186: W/System.err(4219): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
09-18 16:05:20.186: W/System.err(4219): at libcore.io.IoBridge.open(IoBridge.java:403)