这样下载的网页为什么在记事本中显示和控制台上不一样???
我利用以下程序下载一个网页:
import java.io.*;
import java.net.URL;
import javax.swing.*;
//只下载每页的内容
public class ReadSina {
public static void main(String[] args) throws IOException{
String shuru;
int b;
String str="";
shuru=JOptionPane.showInputDialog("Input an URL:");
FileWriter fw=new FileWriter("D://hanhan.txt",true);
URL url = new URL(shuru); //读取URL
InputStream is = url.openStream();
BufferedInputStream bis = new BufferedInputStream(is); //封装成缓存,提高效率
while((b=bis.read())!=-1)
{str = str+(char)b;}
is.close();
bis.close();
try{
str = new String(str.getBytes("ISO-8859-1"),"UTF-8"); //以ISO-8859-1读取,以GB2312存起来
}catch(Exception e){System.out.println ("sorry");}
fw.write(str);
System.out.println (str);
}
}
程序运行时输入:http://blog.sina.com.cn/twocold
结果是在控制台上显示的内容和积存在D盘上的内容不一样,主要是格式乱了,请问高手应该怎样解决???
回答列表
- 编辑器不一样的, 产生的格式或乱码是很正常的!!
- 相关内容
- 最近更新
- ·vb如何获得光驱盘符?
- ·一道QB题,请给出源程序并说明,..
- ·http_load byte count wrong
- ·这个算法对吗?
- ·如何进行电脑程序学习?
- ·求助。用C或者C++编程
- ·请详细列出VB6及VB.net的语法规则..
- ·C语言问题~COMING..
- ·怎么回事,这个C++程序?
- ·如何将WORD的表格内容添加到一个..
添加到百度搜藏