-
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.
-
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.
-
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();
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks