This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting Font while writing to a Text File

 
Reji Retnaraj
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Text files have no notion of formatting, fonts and styles. You'll need to use some other file format that does, like RTF.
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic