I want to move file from one path to another path but instead of moving it copy the file to new location.
Kindly provide any hints
Thanks in advance
MovePngToPreviewDir pngToPreviewDir = new MovePngToPreviewDir(null, "png");
File[] listOfPNGFiles = RootDir.listFiles(pngToPreviewDir);
for(File file:listOfPNGFiles){
Log.e("PNG = ",file.getAbsolutePath());
Log.e("PNG = ",file.getName());
if(previewDiagramDir == null){
Log.e("Preview Diagram Dir is NULL","Preview Diagram DIR is NULL");
}
if(file!= null && previewDiagramDir != null){
Log.e("Preview Diagram Dir",previewDiagramDir.getAbsolutePath()+"/");
if(file.renameTo(new File(previewDiagramDir, file.getName()))){
Log.e("PNG File is successfully Moved",file.getName());
}else{
Log.e("Error in Moving PNG File","Error in Moving PNG file");
}
}else{
}
If you want to copy the file to another location, you can use
file.renameTo()method ofFileclass, related to your istance objectfile, trying this:After copying the file, you can delete it with
file.delete();.Note: The method
delete()returns a boolean object, then you can check the correct file deletion with:About the
Fileclass API: http://download.oracle.com/javase/6/docs/api/java/io/File.html