Reputation: 23
I am writing information to a text file, how do i I change the font size for Data that i am writing to the text file. also how do you set the data to be written in bold or underlined.
Upvotes: 2
Views: 11568
Reputation: 598
As all people say .txt files don't have format options.
I want to clarify something
It's possible have a txt file with specific format.
The way to do it is with a specific viewer:
You can add style, text size with notepad
You can add underlines or line spacing with notepad++
depending on you txt viewer you can postformat.
Then a possible solution would be POSTFORMATING, it works, for example if you want to print your file, only change setting on your viewer and you could obtain the result that you are looking for.
I'm working in this way for printing my txt reports.
Upvotes: 0
Reputation: 40378
Actually, the .txt format does not contain formatting such as font size, bond, italics, etc.
You probably want to use a markup language
like html
, or another file format, such as rtf
, pdf
or something else.
Here's some information on learning html: w3schools.com
And a java library for writing rtf: srw library
And a java library for writing pdf: pdfbox
Good luck.
Upvotes: 5
Reputation: 521
Supposing you are editing your text in a JTextArea you might do this:
this.textArea.setFont(new Font("Arial", Font.PLAIN, 12));
//the code comments itself
if you want bold
then write Font.BOLD
As someone already told you, unfortunately plain .txt
files don't contain formatting. If you need to format the text, you should change format and try HTML
.
Upvotes: 0
Reputation: 3592
Plaintext files do not have format and style options.
For this you would have to write the data in a different format. E.g. html if you want to view it in a browser later. But the format you chose greatly depends upon how and by whom those data should be read.
Upvotes: 2