CopyFile
Aus Programmers Guide
(Unterschied zwischen Versionen)
Roy (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „public static boolean copyFile(String fileIn,String fileOut) { try {<br> File f1 = new File(fileIn);<br> File f2 = new File(fileOut);<br> InputStream in = new Fi…“) |
Roy (Diskussion | Beiträge) |
||
Zeile 1: | Zeile 1: | ||
+ | <source lang="java"> | ||
public static boolean copyFile(String fileIn,String fileOut) { | public static boolean copyFile(String fileIn,String fileOut) { | ||
+ | try { | ||
+ | File f1 = new File(fileIn); | ||
+ | File f2 = new File(fileOut); | ||
+ | InputStream in = new FileInputStream(f1); | ||
+ | OutputStream out = new FileOutputStream(f2); | ||
+ | byte[] buf = new byte[1024]; | ||
+ | int len; | ||
+ | while ((len = in.read(buf)) > 0) { | ||
+ | out.write(buf, 0, len); | ||
+ | } | ||
+ | in.close(); | ||
+ | out.close(); | ||
+ | return true; | ||
+ | } catch (FileNotFoundException ex) { | ||
+ | return false; | ||
+ | } catch (IOException e) { | ||
+ | return false; | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
- | + | [[Category:Funktionen]] [[Category:Java]] | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | [[Category:Funktionen]][[Category:Java]] | + |
Aktuelle Version vom 09:34, 30. Mär. 2010
public static boolean copyFile(String fileIn,String fileOut) { try { File f1 = new File(fileIn); File f2 = new File(fileOut); InputStream in = new FileInputStream(f1); OutputStream out = new FileOutputStream(f2); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); return true; } catch (FileNotFoundException ex) { return false; } catch (IOException e) { return false; } }