//mjava socket通信(读取URL)
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.net.URL;
public class xiao7 {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// 声明抛出所有例外
//URL tirc = new URL(http://www.sina.com);
File writeFile = new File("d:\\style_1.html");
// 构建一URL对象14100
BufferedReader in = new BufferedReader(new InputStreamReader(tirc.openStream()));
BufferedWriter bos = new BufferedWriter(new FileWriter(writeFile));
byte[] b=new byte[4096];
String inputLine;
// 使用openStream得到一输入流并由此构造一个BufferedReader对象
while ((inputLine = in.readLine()) != null){
bos.write(inputLine);
System.out.println(inputLine);
}
bos.flush();
in.close();
bos.close();
}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.net.URL;
public class xiao7 {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// 声明抛出所有例外
//URL tirc = new URL(http://www.sina.com);
File writeFile = new File("d:\\style_1.html");
// 构建一URL对象14100
BufferedReader in = new BufferedReader(new InputStreamReader(tirc.openStream()));
BufferedWriter bos = new BufferedWriter(new FileWriter(writeFile));
byte[] b=new byte[4096];
String inputLine;
// 使用openStream得到一输入流并由此构造一个BufferedReader对象
while ((inputLine = in.readLine()) != null){
bos.write(inputLine);
System.out.println(inputLine);
}
bos.flush();
in.close();
bos.close();
}
}
但我不知道那错了
new URL("http://www.sina.com");莫非是双引号的问题?
URL(String protocol, String host, int port, String file)
根据指定 protocol、host、port 号和 file 创建 URL 对象。
URL(String protocol, String host, int port, String file, URLStreamHandler handler)
根据指定的 protocol、host、port 号、file 和 handler 创建 URL 对象。
URL(String protocol, String host, String file)
根据指定的 protocol 名称、host 名称和 file 名称创建 URL。
URL(URL context, String spec)
通过在指定的上下文中对给定的 spec 进行解析创建 URL。
URL(URL context, String spec, URLStreamHandler handler)
通过在指定的上下文中用指定的处理程序对给定的 spec 进行解析来创建 URL。