2

I am using JTidy i want to give it a string as an input instead of a file. Is that possible? How i can do that?

This is my code:

    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"));  
    }  
4

1 回答 1

3

将 替换为FileInputStream从 a 读取的流String,例如

try   
{
    fis = new ByteArrayInputStream(string.getBytes());
}  catch (java.io.IOException e) {  
    System.out.println("Error reading string");
    return;
}  
于 2013-03-11T11:27:21.980 回答