mehdi
asked on
Copying Files
People,
Which class, or set of classes facilitate the copying of files ? Please note that I dont really want to open a file, read it in and write its contents to another file, i want to actually do a proper copy.
There must be a class that will allow
myObj.copyFile("from", "to");
// or maybe from and to would be File objects.
Please tell me that there is a class that will do this. A code snippet would be helpful too .
Cheers
Mehdi
Which class, or set of classes facilitate the copying of files ? Please note that I dont really want to open a file, read it in and write its contents to another file, i want to actually do a proper copy.
There must be a class that will allow
myObj.copyFile("from", "to");
// or maybe from and to would be File objects.
Please tell me that there is a class that will do this. A code snippet would be helpful too .
Cheers
Mehdi
ASKER
This question has already been answered.. i posted the question twice by accident.. darn refresh :)
Sorry.. I will now write and ask them to remove this repeat question.
Mehdi
Sorry.. I will now write and ask them to remove this repeat question.
Mehdi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is a simple Example of the copyFile() method:
public void copyFile(String src, String dest) throws IOException
{
InputStream is = new FileInputStream(src);
OutputStream os = new FileOutputStream(dest);
byte[] buffer = new byte[0xffff]; // buffer size = FFFF hex
int nbytes;
while ((nbytes = is.read(buffer)) != -1)
{
os.write(buffer, 0, nbytes);
} // while ((nbytes = is.read(buffer)) != -1)
is.close();
os.close();
} // public void copyFile(String)