How to copy files in Java?
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sauarbh_kumar
Posted On:   Friday, August 31, 2001 08:57 AM

How can I copy files on disk using Java
API?

Thanks

Re: How to copy files in Java?

Posted By:   John_Zukowski  
Posted On:   Friday, August 31, 2001 05:18 PM

The FAQ already answers this: How do I copy a file?

Re: How to copy files in Java?

Posted By:   Virgilio_Garcia  
Posted On:   Friday, August 31, 2001 09:27 AM

For transfer any byte in Java require utilize Streams


import java.io.*;

public class CopyFiles {
FileInputStream source;
FileOutputStream destino;
// "source" and "destino" are path absolute.
public CopyFiles(String source, String destino) {
try {
this.source = new FileInputStream(source);
this.destino = new FileOutputStream(destino);
copyFile();
}catch(Exception ex) {
ex.printStackTrace();
}
}
public void copyFile() throws Exception {
int i = source.read();
while (i !=-1) {
destino.write(i);
i = source.read();
}
destino.flush();
source.close();
}
}

Re: How to copy files in Java?

Posted By:   AlessandroA_Garbagnati  
Posted On:   Friday, August 31, 2001 09:20 AM

Hi,

Check this document out...
About | Sitemap | Contact