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

1 Answer 1

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;
}  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.