Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing File Dialog Box  RSS feed

 
Prasad Ballari
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Can anybody help me out?. I am writing one Notepad application, there i require OS's SAVE dialog box.Now i am getting the Save Dialog box. But How to save a String that is Where the user types (Like NotePad) to a file. and similarly how get a file and show it in to the TextArea object.
The code is like this.
[here sn is the frame(defined earlier).]
FileDialog fldSave=new FileDialog(sn,"Simple Save DialogBox",FileDialog.SAVE);
fldSave.setVisible(true);

Regards
Prasad

------------------
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From here it's something like.
String dir = fldSave.getDirectory();
String fileName = fldSave.getFile();
File outFile = new File(dir, fileName);
BufferedOutputStream bf = new BufferedOutputStream(new FileOutputStream(outFile));
String text = textArea.getText();
bf.write(text.getBytes());
bf.flush();
bf.close();
To read in text and display it.
String dir = fldOpen.getDirectory();
String fileName = fldOpen.getFile();
File outFile = new File(dir, fileName);
BufferedReader br = new BufferedReader(new FileReader(outFile));
String lineIn = "";
while((lineIn = br.readLine()) != null;
{
textArea.append(lineIn + "\r\n");
}
Hope this helps

[This message has been edited by Carl Trusiak (edited October 18, 2000).]
 
Prasad Ballari
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carl Trusiak
Thank u very much.Its really fantstic.It works.I tried with FileWriter & FileReader. Its working.
Once again thank you for your advicing me for Concept.

Regards
Prasad Ballari.
------------------
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!