Download New Sharecodepoint Android App from Google Play Store : DocScannerPoint : Document Scanner with OCR, PDF: Download Now


Domyhomework123.com - programming homework help. Get your programming homework done with expert homework helper. Trust Writemypaper123.com with your paper and you will never regret it.

Download Latest Notes, Study Materials and More...

Visit: Download Now


Ask Any Question Relative to your Sujbect

Visit: Ask Question


Copy all Files and Folder from Folder in Android studio.

How to copy files from the folder in android studio. please try this:

Example :

AppManifest in the project. Please allow this permission to read and write external storage.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
public static void copyFileOrDirectory(String srcDir, String dstDir) {
 
        try {
            File src = new File(srcDir);
            File dst = new File(dstDir, src.getName());
 
            if (src.isDirectory()) {
 
                String files[] = src.list();
                int filesLength = files.length;
                for (int i = 0; i < filesLength; i++) {
                    String src1 = (new File(src, files[i]).getPath());
                    String dst1 = dst.getPath();
                    copyFileOrDirectory(src1, dst1);
 
                }
            } else {
                copyFile(src, dst);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    public static void copyFile(File sourceFile, File destFile) throws IOException {
        if (!destFile.getParentFile().exists())
            destFile.getParentFile().mkdirs();
 
        if (!destFile.exists()) {
            destFile.createNewFile();
        }
 
        FileChannel source = null;
        FileChannel destination = null;
 
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } finally {
            if (source != null) {
                source.close();
            }
            if (destination != null) {
                destination.close();
            }
        }
    }

0 Comments

Post a Comment