Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copying files from sdcard to android internal storage directory

Tags:

android

I have created a directory in android internal storage using following lines:

File directory = getDir("template", Context.MODE_PRIVATE);

I need to add some files in this 'template' directory from sdcard, what is the way to achieve this?

Any help is appreciated..

Thanks

like image 299
Neo Avatar asked Feb 23 '23 07:02

Neo


1 Answers

try using this method. in that you should give source and destination file names.

private boolean copyFile(File src,File dst)throws IOException{
        if(src.getAbsolutePath().toString().equals(dst.getAbsolutePath().toString())){

            return true;

        }else{
            InputStream is=new FileInputStream(src);
            OutputStream os=new FileOutputStream(dst);
            byte[] buff=new byte[1024];
            int len;
            while((len=is.read(buff))>0){
                os.write(buff,0,len);
            }
            is.close();
            os.close();
        }
        return true;
    }
like image 76
ilango j Avatar answered May 14 '23 10:05

ilango j