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 Setting Font while writing to a Text 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 "Setting Font while writing to a Text File" Watch "Setting Font while writing to a Text File" New topic
Author

Setting Font while writing to a Text File

Reji Retnaraj
Greenhorn

Joined: Jan 05, 2010
Posts: 1
Hi,

I am generating a .txt file using RandomAccessFile. Now I need to set the font of some of its lines to be bold and also want to display fonts other than English.

Can you help me in this.

--Reji--
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41108
    
  45
Text files have no notion of formatting, fonts and styles. You'll need to use some other file format that does, like RTF.


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

Reji Retnaraj wrote:I am generating a .txt file using RandomAccessFile. Now I need to set the font of some of its lines to be bold

Text files have no formatting. Are you sure it isn't a Word (.doc) or RTF file you want to create?

and also want to display fonts other than English.

English isn't a font, it's a language. Arial, Times New Roman, Courier New, those are fonts. English, German, French, those are languages.
However, I think I know what you mean. You want to use non-ASCII characters like é, ö. ß, € and £. That is quite possible with text files if you discard using RandomAccessFile.

You see, RandomAccessFile works on bytes. While ASCII characters can be mapped onto bytes without a problem, most other characters cannot. Therefore, you need to use a Writer. Unlike OutputStream and RandomAccessFile, Writer is designed to handle characters. In short it works like this:
That said, this will again not have any formatting. To create Word or RTF documents, check out http://faq.javaranch.com/java/AccessingFileFormats


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting Font while writing to a Text File
 
Similar Threads
file read/write
how to change the font-family in XSLT file
JeditorPane Font
Loading Font through .ttf file but issue with the size
Exception