File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes To Convert a .txt file into .html file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "To Convert a .txt file into .html file" Watch "To Convert a .txt file into .html file" New topic
Author

To Convert a .txt file into .html file

Ramya Thyagarajan
Greenhorn

Joined: Jun 27, 2005
Posts: 15
Hi,

I have a .txt file generated by my program but I require the contents of the file generated to be displayed in a HTML window.

Is it possible to move the contents of a .txt file into a .html file without hampering the format?
James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
Your browser should be able to successfully render the .txt file without needing to convert the file to html. A .txt file is about as simple as it gets and any browser built within the last 3 years should be able to handle it.
Casper Maxwell
Ranch Hand

Joined: Aug 04, 2005
Posts: 88
You may do the conversion like this:

Text file:

"Just try sth. Do sth.

And do sth different."

Html file:

"
<html>
<body>
<p>Just try sth. Do sth.</p>

<p>And do sth different.</p>
</body>
</html>
"

So you can add a <p> tag to each of you paragraphes(You may search for two newlines in your text to determine paragraph positions. "\n\n") and add some header(e.g. <html> and trailer (</html> tags...
Karthikeyan Rajendraprasad
Ranch Hand

Joined: Apr 16, 2003
Posts: 70
just rename the .txt file to .html file... that would do. no need to have html tags


Karthikeyan<br />SCJP 1.4, SCWCD.
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
Just slap an HTML header on the top of the file



Oh yeah, you'll also have to escape things like angle brackets and ampersands with their corresponding HTML escape codes.

Geoffrey


Sun Certified Programmer for the Java 2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To Convert a .txt file into .html file