Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要使用 java 代码获取特定 URL 的源代码。我能够获得 UTF-8 编码网页的源代码,但无法获得 ISO-8859-1 编码字符集的代码。我的问题,是否可以使用 java 程序获取带有 iso-8859-1 的网站源代码?请帮忙
如果您使用以下方法阅读,则需要通过以下方式明确指定字符集
URL url = new URL(URL_TO_READ); BufferedReader in = new BufferedReader( new InputStreamReader(url.openStream(),"ISO-8859-1" ));
但是,如果您的要求中包含很少的解析,我建议您使用JSOUP,它会从服务器的响应中读取字符集,您也可以显式设置字符集