ITeye博客

URL 获取网页内容乱码解决

shen211 · 2010-09-02 10:31 · java · 企业架构 · Markdown


in = url.openStream();
			int all = url.openConnection().getContentLength();
			byte[] b = new byte[all];
    		int index = 0;
    		int count = in.read(b, index, all);
		    while (count != -1) {
		      index += count;
		      count = in.read(b, index, 1);
		    }
			String  str = new String(b, "gb2312");

注意:获取用byte读取内容,其他的如字符串读取,则不能解决问题

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。