Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java:Jtidy从html文本到xhtml文本的转换_Java_Html_Xhtml_Jtidy - Fatal编程技术网

Java:Jtidy从html文本到xhtml文本的转换

Java:Jtidy从html文本到xhtml文本的转换,java,html,xhtml,jtidy,Java,Html,Xhtml,Jtidy,我正在使用JTidy,我想给它一个字符串作为输入,而不是文件。可能吗? 我怎么能做到 这是我的代码: FileInputStream fis =null; String htmlFileName = "report.html"; //from html to xhtml try { fis = new FileInputStream(htmlFileName); } catch (java.io.Fi

我正在使用JTidy,我想给它一个字符串作为输入,而不是文件。可能吗? 我怎么能做到

这是我的代码:

    FileInputStream fis =null;  
    String htmlFileName = "report.html";  

   //from html to xhtml
   try   
    {  
        fis = new FileInputStream(htmlFileName);  
    }  
    catch (java.io.FileNotFoundException e)   
    {  
        System.out.println("File not found: " + htmlFileName);  
    }  
        Tidy tidy = new Tidy(); 
        tidy.setShowWarnings(false);
        tidy.setXmlTags(false);
        tidy.setInputEncoding("UTF-8");
        tidy.setOutputEncoding("UTF-8");
        tidy.setXHTML(true);// 
        tidy.setMakeClean(true);
        Document xmlDoc = tidy.parseDOM(fis, null);  
    try  
    {  
        tidy.pprint(xmlDoc,new FileOutputStream("report.xhtml"));  
    }  

文件输入流
替换为从
字符串
读取的流,例如

try   
{
    fis = new ByteArrayInputStream(string.getBytes());
}  catch (java.io.IOException e) {  
    System.out.println("Error reading string");
    return;
}