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"));  
    }  
Henrik Aasted Sørensen
  • 6,966
  • 11
  • 51
  • 60
mohammad
  • 2,142
  • 7
  • 35
  • 60

1 Answers1

3

Replace the FileInputStream with a stream that reads from a String, e.g.

try   
{
    fis = new ByteArrayInputStream(string.getBytes());
}  catch (java.io.IOException e) {  
    System.out.println("Error reading string");
    return;
}  
Henrik Aasted Sørensen
  • 6,966
  • 11
  • 51
  • 60