/* Tekstifaili kopeerimine. Kasutamisel tuleb parameetritena pakkuda lähtefaili nime ja koopia nime. Näiteks java CopyFile FIRST.TXT SECOND.TXT */ import java.io.*; class CopyFile { public static void main(String args[]) throws IOException { int i; FileInputStream fin; FileOutputStream fout; try { fin = new FileInputStream(args[0]); fout = new FileOutputStream(args[1]); } catch(FileNotFoundException e) { System.out.println("Ei leidnud faili"); return ; } catch(IOException e) { System.out.println("Väljundfaili avamise viga"); return ; } catch(ArrayIndexOutOfBoundsException e) { System.out.println("Kasutamissüntaks: CopyFile lähtefail tulemifail"); return ; } // Copy File try { do { i = fin.read(); if(i != -1) fout.write(i); } while(i != -1); } catch(IOException e) { System.out.println("Failis viga"); } fin.close(); fout.close(); } }