You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Start.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package chatprogramm;
  7. import java.io.BufferedInputStream;
  8. import java.io.BufferedOutputStream;
  9. import java.io.File;
  10. import java.io.FileOutputStream;
  11. import java.io.IOException;
  12. import java.io.InputStream;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. /**
  16. * Builder Class
  17. * @author le
  18. */
  19. public class Start
  20. {
  21. public Start(String urlString, String dateiname) throws MalformedURLException, IOException
  22. {
  23. URL oUrl = new URL(urlString + "/" + dateiname);
  24. InputStream iStream = oUrl.openStream();
  25. BufferedInputStream in = new BufferedInputStream(iStream);
  26. String tmpVerzeichnis = System.getProperty("java.io.tmpdir");
  27. String ausgabeDateiname = tmpVerzeichnis + File.separator + dateiname;
  28. FileOutputStream fos = new FileOutputStream(ausgabeDateiname);
  29. BufferedOutputStream out = new BufferedOutputStream(fos);
  30. int wert = 0;
  31. while ( (wert = in.read()) >= 0)
  32. {
  33. out.write(wert);
  34. }
  35. in.close();
  36. out.close(); // flush!
  37. System.out.println("Datei " + ausgabeDateiname + " erfolgreich erstellt");
  38. }
  39. /**
  40. * @param args the command line arguments
  41. */
  42. public static void main(String[] args)
  43. {
  44. if (args.length != 2)
  45. {
  46. System.err.println("2 Aufrufparameter nötig: URL-String Dateiname");
  47. }
  48. else
  49. {
  50. try
  51. {
  52. new Start(args[0], args[1]);
  53. }
  54. catch (Exception ex)
  55. {
  56. System.err.println(ex);
  57. ex.printStackTrace();
  58. }
  59. }
  60. }
  61. }