0

For past couple of days I had been trying to copy files from usb flash drive to my nexus 7 memory. Is there a way to transfer the files without having to specify the file name? here is my code so far.

 public void copyFile(File usb, File dst) throws IOException 
    {
        //checks to see if the backup directory is created
        if(dst.isDirectory())
        {
            //displays message saying directory is created
            mvfldr.show();
            //if else statement checks to see if pen drive drive is connected

            if(!usb.exists())
            {
                //displays message if pen drive is not connected
                chkffd2.show();

            }
            else
            {
                //displays pen drive is connected to the device
                chkffd.show();
                String[] children = usb.list();
                for(int i=0; i<children.length; i++)
                {
                    copyFile(new File(usb, children[i]), new File(dst, children[i]));
                }
            }

        }
        //directory is not created, and create the directory.
        else
        {
            //displaying message saying folder has not been created, and will be created.
            bldng.show();
            dst.mkdir();

            if(!usb.exists())
            {
                //displaying flash drive has not been connected
                chkffd2.show();

            }
            else
            {
                //displaying flash drive had been connected.
                chkffd.show();
                String[] children = usb.list();
                for(int i=0; i<children.length; i++)
                {
                    copyFile(new File(usb, children[i]), new File(dst, children[i]));
                }

            }

        }
        InputStream in = new FileInputStream(usb);
        OutputStream out = new FileOutputStream(dst);

        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0);
        {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
    }

});
}
}
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
andyADD
  • 610
  • 1
  • 6
  • 20
  • Take a look at this question, looks like what you're looking for: http://stackoverflow.com/questions/5368724/how-to-copy-a-folder-and-all-its-subfolders-and-files-into-another-folder – Anton Cherkashyn Dec 10 '12 at 04:57
  • Erm, that is the same way I have my code. but mine only pull folders not the files. – andyADD Dec 10 '12 at 05:12

0 Answers0