Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class CopyFile {
- public static void main(String[] args) throws IOException
- {
- int i;
- FileInputStream fin = null;
- FileOutputStream fout = null;
- // First, make sure that both files has been specified.
- if(args.length != 2) {
- System.out.println("Usage: Copy File from to");
- return;
- }
- // Copy a File
- try {
- // Attempt to open the files
- fin = new FileInputStream(args[0]);
- fout = new FileOutputStream(args[1]);
- do {
- i = fin.read(); // Read bytes from one file
- if(i != -1) fout.write(i); // and write them to another
- } while(i != -1);
- } catch(IOException exc) {
- System.out.println("I/O Error: " + exc);
- } finally {
- try {
- if(fin != null) fin.close();
- } catch(IOException exc) {
- System.out.println("Error Closing Input File");
- }
- try {
- if(fout != null) fin.close();
- } catch(IOException exc) {
- System.out.println("Error Closing Output File");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement