Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to easily write a text file with beautiful format

 
Pira Tomatsu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I'm a java beginner. I need to write text from database into a beautiful format text file such as a POS slip format.
Can you give me an advice of what I need to know to do things like this.

Thank you very much
 
Karina Guenther
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One method is to write your output as comma delimited format using BufferedWriter that your user can open in a spreadsheet. The spreadsheet program then organizes your information in the way you want it.

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(response
.getOutputStream()));

If this is interactive and you are returning the data as part of a gui response, you can set the headers in your response to automatically activate the application you want your document to use.

example:
response.setContentType("text/csv");
response.setHeader("content-disposition", "attachment; filename=\""
+ fileName + "\"");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic