DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    srinu Guest

    Text to HTML translators using Java Utility/Java Class.


    I am having a text file. I need to save it into HTML format. How can I do
    this using Java.
    Is there any ready made Java Utility/Java Class available for converting
    text to HTML.
    I mean which will take a text file as input and outputs HTML file. When I
    searched on
    Internet I got so many Perl-translators which will do this but I need to
    do this using only
    Java Utility/Java Class. This is very critical to my project.Please let
    me know as soon
    as possible if such kind of Utility is availbale.

    Thanks & Regards,
    Srinu.

  2. #2
    brundavanam Guest

    Re: Text to HTML translators using Java Utility/Java Class.


    i think by using filechooser you can save any file as the format you want
    to be

    try it out.






    "srinu" <nlgsrinu@hotmail.com> wrote:
    >
    >I am having a text file. I need to save it into HTML format. How can I do
    >this using Java.
    >Is there any ready made Java Utility/Java Class available for converting
    >text to HTML.
    >I mean which will take a text file as input and outputs HTML file. When

    I
    >searched on
    >Internet I got so many Perl-translators which will do this but I need to
    >do this using only
    >Java Utility/Java Class. This is very critical to my project.Please let
    >me know as soon
    >as possible if such kind of Utility is availbale.
    >
    >Thanks & Regards,
    >Srinu.



  3. #3
    Join Date
    Apr 2009
    Posts
    1

    Try this!

    public void changeTextToHtml(String inputTxtFile)
    {
    String [] temp = inputTxtFile.split(".");
    String s,formName = "testForm";
    try{
    File txtFile = new File(inputTxtFile);
    File htmlFile = new File(inputTxtFile+".html");
    FileReader txtFileReader = new FileReader(txtFile);
    BufferedReader txtBuffReader = new BufferedReader(txtFileReader);
    PrintWriter htmlPrintWriter = new PrintWriter(htmlFile);
    htmlPrintWriter.println("<html>");
    htmlPrintWriter.println("<head>");
    htmlPrintWriter.println("<script>");
    //Write your script here using following
    htmlPrintWriter.println("function alertUser(){");
    htmlPrintWriter.println("alert('Created by ravi');");
    htmlPrintWriter.println("}");
    htmlPrintWriter.println("</script>");
    htmlPrintWriter.println("</head>");
    htmlPrintWriter.println("<form name ="+formName+" >");
    htmlPrintWriter.println("<body onLoad='alertUser()'>");
    //Start reading file line by line and write into the html file
    while((s=txtBuffReader.readLine())!=null)
    {
    htmlPrintWriter.println("<h1>"+s);
    htmlPrintWriter.println("<br>");
    }
    htmlPrintWriter.println("</body>");
    htmlPrintWriter.println("</form>");
    htmlPrintWriter.println("</html>");

    htmlPrintWriter.close();
    txtBuffReader.close();

    }catch(Exception e)
    {
    e.printStackTrace();
    }

    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links