|
How to create a duplicate of one file in another directory |
|
|
This Java tip demonstrates a method of copying one file to another file. Developer may use file streams to copy the contents of the file.
// Copy the source file to target file.
// In case the dst file does not exist, it is created
void copy(File source, File target) throws IOException {
InputStream in = new FileInputStream(source);
OutputStream out = new FileOutputStream(target);
// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.