DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Python - GetFile Internet

09.30.2006
| 5585 views |
  • submit to reddit
        // Scaricare un file dalla rete

package get.file.example;

import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

public class GetFileExample
{
	public GetFileExample()
	{
		try
		{
			byte[] bite = new byte[2048];
			int read;
			URL url = new URL("http://switch.dl.sourceforge.net/sourceforge/pys60miniapps/FlickrS60_src_v0.1b.tar.bz2");
			
			BufferedInputStream bis = new BufferedInputStream(url.openStream());
			FileOutputStream fos = new FileOutputStream("/tmp/file.tar.bz2");
			
			while((read = bis.read(bite))>0)
			{
				fos.write(bite, 0, read);
				System.out.println("--");
			}
			
			fos.close();
			bis.close();
			
			System.out.println("FINE");
			
		}
		catch(MalformedURLException e)
		{
			e.printStackTrace();
		}
		catch(IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args)
	{
		new GetFileExample();
	}
}