i am using below code to copy multiple files from one folder to another , but it takes too much time , it is requested is their any best practice to implement to increase speed. i will be grateful.( Note: i am not moving files )
void copyFile(File sourceLocation, File targtLocation) throws IOException { if (sourceLocation.exists()) { InputStream in = null; OutputStream out = null; try { in = new FileInputStream(sourceLocation); new File(String.valueOf(targtLocation)).delete(); out = new FileOutputStream(targtLocation); } catch (FileNotFoundException e) { e.printStackTrace(); } // Copy the bits from instream to outstream byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); sourceLocation.delete(); Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); scanIntent.setData(Uri.fromFile(sourceLocation)); sendBroadcast(scanIntent); Log.e("debug", "Copy file successful."); } else { Log.v("debug", "Copy file failed. Source file missing."); } }