I made this method to copy file from inputpath to outputpath. It works when input is located in sdcard, and output is located in local storage, But when I change output to a file located in sdcard, it doesn't work and doesn't show any error. How can I fix this???
I checked output with file.canwrite() and it returned false.. Why??
public void copyFile(String inputPath, String outputPath) { FileInputStream fis = null; FileOutputStream fos = null; FileChannel in = null; FileChannel out = null; try{ fis = new FileInputStream(inputPath); fos = new FileOutputStream(outputPath); in = fis.getChannel(); out = fos.getChannel(); in.transferTo(0, in.size(), out); } catch(Exception e){ e.printStackTrace(); } finally { try{ if(out != null) out.close(); if(in != null) in.close(); if(fis != null) fis.close(); if(fos != null) fos.close(); } catch (Exception e) { e.printStackTrace(); } }
}