File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes opening and saving using JFileChooser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "opening and saving using JFileChooser" Watch "opening and saving using JFileChooser" New topic
Author

opening and saving using JFileChooser

shreehari Gopalakrishnan
Ranch Hand

Joined: Jun 01, 2004
Posts: 30
Hi masters

one of my current project needs a notepad like application,
in that we have to choose and save the files automatically

i have used JFileChooser and displayed the dialog box
but problem is i have to get that content of the file from the path and display in a JTextArea

i can get from from the file contents as characters if i use FileInputStream class

then i cannot append to JTextArea

so can u please give me a sample code for choosing a file and displaying in a <b>JTextArea </b> and saving it to a file name using JFileChooser
<b>It is very urgent</b>
Thanks in advance
Ben Buchli
Ranch Hand

Joined: Mar 26, 2004
Posts: 83
once you got the content of your file stored as a string (or StringBuffer) use


hope that helps
[ June 22, 2004: Message edited by: Ben Buchli ]
shreehari Gopalakrishnan
Ranch Hand

Joined: Jun 01, 2004
Posts: 30
But how can i get the files in string
I can get only as characters

please tell me how we can convert a char to String
Ben Buchli
Ranch Hand

Joined: Mar 26, 2004
Posts: 83
you may want to use a BufferedReader, that way you get each line of the file as a string...

something like this will work:

You need the try block because this code may throw a FileNotFoundException, or a IOException.

hope that helps
[ June 23, 2004: Message edited by: Ben Buchli ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the I/O and Streams forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: opening and saving using JFileChooser