java中通过url获取网页内容,中文显示是乱码
java中通过url获取网页内容,中文显示是乱码,请问怎么解决?publicvoiddownloadPage(URLpageUrl){try{//Openconnecti...
java中通过url获取网页内容,中文显示是乱码,请问怎么解决?
public void downloadPage(URL pageUrl) {
try {
// Open connection to URL for reading.
BufferedReader reader = new BufferedReader(new InputStreamReader(
pageUrl.openStream()));
// Read page into buffer.
String line;
StringBuffer pageBuffer = new StringBuffer();
while ((line = reader.readLine()) != null)
{
pageBuffer.append(line);
}
System.out.println(pageBuffer.toString());
//return pageBuffer.toString();
}
catch (Exception e)
{
// return null;
}
}
这是代码 展开
public void downloadPage(URL pageUrl) {
try {
// Open connection to URL for reading.
BufferedReader reader = new BufferedReader(new InputStreamReader(
pageUrl.openStream()));
// Read page into buffer.
String line;
StringBuffer pageBuffer = new StringBuffer();
while ((line = reader.readLine()) != null)
{
pageBuffer.append(line);
}
System.out.println(pageBuffer.toString());
//return pageBuffer.toString();
}
catch (Exception e)
{
// return null;
}
}
这是代码 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询