Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package url;
- import java.io.*;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class UrlZabawa
- {
- public static void main(String[] argumenty)
- {
- String adresPliku = "http://www.personal.psu.edu/ivs5030/plant.jpg";
- try
- {
- URL url = new URL(adresPliku);
- try(InputStream is = url.openStream())
- {
- try(FileOutputStream fos = new FileOutputStream("obrazek_z_internetu.jpg"))
- {
- int bufferSize = 1024;
- int c;
- byte[] buffer = new byte[bufferSize];
- while(( c = is.read(buffer, 0, bufferSize)) != -1)
- {
- fos.write(buffer, 0, c);
- }
- System.out.println("Zapisano obrazek na dysku!");
- }
- }
- catch (IOException ex)
- {
- System.out.println("Wystapil blad ze strumieniem!");
- }
- }
- catch(MalformedURLException e)
- {
- System.out.println("Kijowy adres URL do pliku!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement