import java.net.*;
import java.io.*;
public class ReadURLFile {
public static void main(String[] args){
try
{
URL url = new URL("http://www.baidu.com");
BufferedReader in =new BufferedReader( new InputStreamReader(url.openStream()));
FileWriter file =new FileWriter("text1.txt");
String str;
while ((str=in.readLine())!=null)
{
System.out.println(str);
file.write(str+"/n");
str=in.readLine();
}
in.close();
file.close();
}catch (MalformedURLException e)
{
System.out.println(e.toString());
}catch (IOException el)
{
System.out.println(el.toString());
}
}
}
学习一下 呵呵
最新推荐文章于 2022-02-22 10:23:20 发布