在俺机子上连http://www.sina.com.cn都不可用,连不上???
只能连上自己建的服务器,
yumen O!!!
只能连上自己建的服务器,
yumen O!!!
解决方案 »
- 被杠晕了!
- java类的方法声明和实现是否可以像C++一样分开
- JXL 怎么输出百分数?
- 我看了一天才完全看懂的一个解三元方程组程序分享给大家
- 请教JBuilder中JDBC连接SQL Server数据库?
- JAVA 通过JNI如NT SERVICE 通信
- 写了一个文本编辑器,如何实现查找替换功能?
- java菜菜鸟提问之二:我想下载个jbuilder,哪儿有,我找到的都没序列号。
- 无法注册JDBC驱动程序: oracle.jdbc.driver.OracleDriver是为什么?
- winxp里如何设置package的路径?
- 誰能教我一下在 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());
}}