A text file has no format -- it's just text. To write formatted text to a file, you need to write a file format that supports... formatting. Options include HTML (lots of HTML libaries out there), PDF (the iText library) or
RTF (iText again,) or PostScript (not sure what the best way to do this from
Java is).
But you can't apply a style to a String -- it doesn't really make sense. You can write a String to a file, and also write the formatting information to the file -- but you first have to decide what kind of a file you're writing.