File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Writing Documents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Writing Documents" Watch "Writing Documents" New topic

Writing Documents

Mario Bonassin

Joined: Apr 08, 2004
Posts: 18
I'm trying to write a save action that will write a Document from a JTextComponent to a txt file. I can't seem to figure it out. I've looked at the API and that hasn't gotten me anywhere.
any suggestions
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Try using a FileWriter

SCJP2. Please Indent your code using UBB Code
Mario Bonassin

Joined: Apr 08, 2004
Posts: 18
I've tried all those and it doesn't write a whole document.
FileWriter(document) doesn't work.
Is there something I need to do to the Document of a JTextComponent to make it saveable. Do I need to convert the entire doc to a string and then write each string or can I somehow write the doc as a whole?
this is the document i'm talking about.
Joe Ess

Joined: Oct 29, 2001
Posts: 9168

The documentation for Document directs you to this article on the Element interface. That article directs you to the API documentation for EditorKit which has methods for reading and writing to/from streams.

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: Writing Documents
It's not a secret anymore!