---
title: "URL 获取网页内容乱码解决"
author: "shen211"
date: "2010-09-02T10:31:59Z"
tags: []
categories: ["企业架构"]
slug: "url"
draft: false
lastmod: "2010-09-02T10:31:59Z"
id: 753308
url: "https://shen211.iteye.com/blog/753308"
---

```java

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读取内容，其他的如字符串读取，则不能解决问题