Ragazzi sto scaricando delle pagine web attraverso questo codice:
codice:
while(token.hasMoreTokens())
			{
			Object valore = token.nextElement();
			System.out.println(valore);
			}
		
		}
		 try
	        {
	            URL url = new URL ("http://www.moto.it/index.html");
	            String localFile = "dati.txt";
	            downloadFromUrl (url, localFile, "MyDownloader/1.0");
	        }
	        catch (Exception e)
	        {
	            e.printStackTrace () ;
	        }
	    }

	public static void downloadFromUrl (URL url, String localFilename, String userAgent)
		    throws IOException
		{
		    InputStream is = null;
		    FileOutputStream fos = null;

		    try
		    {
		        URLConnection urlConn = url.openConnection ();
		        urlConn.setRequestProperty ("User-Agent", userAgent) ;

		        is = urlConn.getInputStream ();
		        fos = new FileOutputStream (localFilename);

		        byte[] buffer = new byte[1024];
		        int len;

		        while ((len = is.read (buffer)) > 0)
		            fos.write (buffer, 0, len);
		    }
		    finally
		    {
		        try {
		            if (is != null)
		                is.close ();
		        } finally {
		            if (fos != null)
		                fos.close ();
		        }
		    }
		}
		
	}
Non riesco a capire 2 cose:
- che eccezione è printStackTrace?
- a cosa serve questa funzione urlConn.setRequestProperty ("User-Agent", userAgent) ?
Ho letto sulle api di java ma non riesco a capire bene queste 2 cose