From 5dec5d4e6123a897b0c18241863ea43e7a8ac536 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mei=C3=9Fner?= <daniel@3st.mine.nu>
Date: Tue, 24 Apr 2012 02:15:53 +0200
Subject: [PATCH] Added lesson 4 exercise 1

---
 .../src/FileCopy.java                         | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 Aufgabenblatt_4-Aufgabe_1-Exceptions_deklarieren_und_behandeln/src/FileCopy.java

diff --git a/Aufgabenblatt_4-Aufgabe_1-Exceptions_deklarieren_und_behandeln/src/FileCopy.java b/Aufgabenblatt_4-Aufgabe_1-Exceptions_deklarieren_und_behandeln/src/FileCopy.java
new file mode 100644
index 0000000..62690c5
--- /dev/null
+++ b/Aufgabenblatt_4-Aufgabe_1-Exceptions_deklarieren_und_behandeln/src/FileCopy.java
@@ -0,0 +1,48 @@
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class FileCopy {
+                                                  // geprüfte exceptions
+    public static void main(String[] args) throws FileNotFoundException, IOException {
+        FileInputStream fis = null;
+        FileOutputStream fos = null;
+      
+        // Exception-Handler für ungeprüfte exceptions
+        try {
+          
+          fis = new FileInputStream(args[0]);
+          fos = new FileOutputStream(args[1]);   
+          
+        } catch (ArrayIndexOutOfBoundsException e) {
+          
+          System.out.println("Die Parameterliste beim Programmaufruf sollte sein:");
+          System.out.println("java FileCopy quelldatei zieldatei");
+          return;
+       
+        
+        } catch (Exception e) {
+          
+          if ( !"0".equals(e.getMessage()) ) {
+            System.out.println(e.getMessage());            
+          }else {
+            System.out.println("Ein unerwarteter Fehler trat auf!");            
+          }
+          
+          return;
+        }
+      
+        int c;
+
+        c = fis.read();
+
+        while ( c != -1 ) {
+          fos.write(c);
+          c = fis.read();
+        }
+
+        fis.close();
+        fos.close();
+    }
+}
\ No newline at end of file
-- 
GitLab