java - 为什么 JSOUP 不能读取为 UTF-8?

标签 java html utf-8 jsoup

我想将 jsoup 解析为 utf -8 但我不能。我尝试了我所知道的一切,并在谷歌上进行了搜索。

我的目标是什么:

String tmp_html_content ="Öç";

InputStream is = new ByteArrayInputStream(tmp_html_content.getBytes());            
Document doc_tbl  =  Jsoup.parse(is, "UTF-8", ""); 
doc_tbl.outputSettings().charset().forName("UTF-8");
doc_tbl.outputSettings().escapeMode(EscapeMode.xhtml);

但是 doc_tbl 不是 UTF-8

请帮忙解决

最佳答案

public static void main(String []args){
        System.out.println("Hello World");

        String tmp_html_content ="Öçasasa";

        InputStream is = new ByteArrayInputStream(tmp_html_content.getBytes());            
        org.jsoup.nodes.Document doc_tbl;
        try {
            doc_tbl = Jsoup.parse(is, "ISO-8859-9", "");
              ((org.jsoup.nodes.Document) doc_tbl).outputSettings().charset().forName("UTF-8");
                ((org.jsoup.nodes.Document) doc_tbl).outputSettings().escapeMode(EscapeMode.xhtml);
                String htmlString = doc_tbl.toString();
                System.out.println(htmlString);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        } 

     }

输出

Hello World 奥萨萨萨

关于java - 为什么 JSOUP 不能读取为 UTF-8?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24218239/

相关文章:

c++ - 如何使用boost::spirit解析UTF-8?

java - Android 模拟器 Nexus 5x 加载错误的可绘制大小?

java - StringTokenizer 在 "<br/>"拆分

java - 一个空的父类(super class)?

html - 代码在 jsfiddle 中工作但在我的 html 页面中不起作用

python - 从 python 中的 gzip 文件中读取 utf-8 字符

php - Json 到带有希腊字符的 xml

java - Google App Engine SocketTimeout 异常

php - 无法在 Laravel 中获取 app.scss 的完整文件

Python 美丽汤 : How to find all lowest-level divs (divs which don't contain nested divs)?