Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

opening and saving using JFileChooser

 
shreehari Gopalakrishnan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the I/O and Streams forum...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic