/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package chatprogramm; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; /** * Builder Class * @author le */ public class Start { public Start(String urlString, String dateiname) throws MalformedURLException, IOException { URL oUrl = new URL(urlString + "/" + dateiname); InputStream iStream = oUrl.openStream(); BufferedInputStream in = new BufferedInputStream(iStream); String tmpVerzeichnis = System.getProperty("java.io.tmpdir"); String ausgabeDateiname = tmpVerzeichnis + File.separator + dateiname; FileOutputStream fos = new FileOutputStream(ausgabeDateiname); BufferedOutputStream out = new BufferedOutputStream(fos); int wert = 0; while ( (wert = in.read()) >= 0) { out.write(wert); } in.close(); out.close(); // flush! System.out.println("Datei " + ausgabeDateiname + " erfolgreich erstellt"); } /** * @param args the command line arguments */ public static void main(String[] args) { if (args.length != 2) { System.err.println("2 Aufrufparameter nötig: URL-String Dateiname"); } else { try { new Start(args[0], args[1]); } catch (Exception ex) { System.err.println(ex); ex.printStackTrace(); } } } }