在俺机子上连http://www.sina.com.cn都不可用,连不上???
只能连上自己建的服务器,
yumen O!!!
只能连上自己建的服务器,
yumen O!!!
解决方案 »
- 关于java.beans.EventHandler方法的疑问
- 继承中的构造方法问题
- 比较急!用java查询父节点及路径
- 这个java小程序的输出为什么是这样?
- 请问:我用java的swing组件和sql server 2000数据库,利用eclipse开发了一个资料查询系统,运行结果正常(见里面)
- 异常问题求助
- 菜鸟请教package和import的问题
- 谁能介绍几本好书看
- Swing中至少运行两个线程…………关于事件分发线程Event-dispatching thred
- 初学者:如何在命令行下运行由 JBuilder 编译的工程? ( linux 下 )
- 誰能教我一下在 Websphere studio application developer5.0裡自帶的appSever 裡配置一個oracle連接池,並用一個jsp頁面訪問連接池,100
- 两个错误请教高手(在线等待)
就是读取那个网站的数据不行,别的网站都可以。package com.redv.projects.bittorrent;import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
/**
*
* <p>Title: 配合解析html文件以插入到数据库</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Net {
public Net() {
} public void writeToFile(File file) throws MalformedURLException,
FileNotFoundException, IOException {
System.out.println("Writing file " + file);
try {
int b;
FileOutputStream fos = null;
fos = new FileOutputStream(file);
DataInputStream dis = new DataInputStream(myURL.openStream());
String inputLine;
while ( (b = dis.read()) != -1) {
fos.write(b);
}
dis.close();
fos.close();
}
catch (MalformedURLException me) {
throw new MalformedURLException(me.getMessage());
}
catch (FileNotFoundException ex) {
throw new FileNotFoundException(ex.getMessage());
}
catch (IOException ex) {
throw new IOException(ex.getMessage());
}
} /**
* 从Internet等到网页的源文件
* @return String:source file content
*/
public String getHTML() {
String HTML = new String("");
try {
DataInputStream dis = new DataInputStream(myURL.openStream());
String inputLine;
while ( (inputLine = dis.readLine()) != null) {
HTML = HTML.concat(inputLine);
HTML = HTML.concat("\n");
}
dis.close();
}
catch (MalformedURLException me) {
System.out.println(me);
}
catch (Exception e) {
System.out.println(e);
}
String ret = HTML;
try {
ret = new String(HTML.getBytes("ISO-8859-1"), "GBK");
}
catch (java.io.UnsupportedEncodingException ex) {}
return ret;
} /**
* 设置URL
* @param myURL URL
*/
public void setURL(URL myURL) {
this.myURL = myURL;
} public void setURL(String url) throws java.net.MalformedURLException {
this.myURL = new URL(url);
} public URL getURL() {
return this.myURL;
} private URL myURL; //The Internet URL public static void main(String[] args) throws Exception{
Net net = new Net();
net.setURL("http://www.cumt.edu.cn");
net.writeToFile(new File("C:\\mytest.html"));//正常的输出
System.out.println(net.getHTML());
net.setURL("http://52bt.vicp.net:800/bt/");
net.writeToFile(new File("C:\\mytest2.html"));//不正常的输出
System.out.println(net.getHTML());
}}