Copy Files Android:

Copy files from source to destination:

private void copyFile(String inputPath,String inputFile,String outputPath){
InputStreamin=null;
OutputStreamout=null;
try{
//create output directory if it doesn't existFile 
dir =newFile(outputPath);if(!dir.exists()){
            dir.mkdirs();
}
in=newFileInputStream(inputPath + inputFile);
out=newFileOutputStream(outputPath + inputFile);
byte[] buffer =newbyte[1024];
int read;
while((read =in.read(buffer))!=-1){
out.write(buffer,0, read);
}
in.close();
in=null;
// write the output file (You have now copied the file)
out.flush();
out.close();
out=null;
}catch(FileNotFoundException fnfe1){
Log.e("tag", fnfe1.getMessage());
}catch(Exception e){
Log.e("tag", e.getMessage());
}
}

Add Permission in Androidmanifest:

<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s