java中通过url获取网页内容,中文显示是乱码

2025-01-06 03:14:35
推荐回答(2个)
回答1:

URLConnection context = url.openConnection();
InputStream in = context.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in, "gbk"));
包装流的时候要加入网站的编码 ,gbk和utf-8都试试

回答2:

用UTF-8编码