与えられたUrlに基づいてインターネットからリソースをダウンロード


package demo; 

import java.io.BufferedReader; 
import java.io.BufferedWriter; 
import java.io.File; 
import java.io.FileWriter; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.InputStreamReader; 
import java.io.Reader; 
import java.net.URL; 
import java.net.URLConnection; 

public class DownLoading { 
public static void main(String[] args) throws IOException { 
  String urlName=""; 
  //         Uniform resource locator 
  URL url=new URL(urlName); 
  //     
  URLConnection connection=url.openConnection(); 
  connection.connect(); 
  //      
  InputStream in=connection.getInputStream(); 
  //                
  Reader r=new InputStreamReader(in); 
  //        
  BufferedReader br=new BufferedReader(r); 
  
  
  FileWriter fw=new FileWriter("c:/aa"); 
  BufferedWriter bw= new BufferedWriter(fw); 
  int n=1; 
  String line; 
  while((line=br.readLine())!=null){ 
   bw.write(line); 
   bw.newLine(); 
  } 
  
  br.close(); 
  r.close(); 
  bw.close(); 
  
System.out.println("- ok -"); 
} 
}