• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Accessing File Dialog Box

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

------------------
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
------------------
reply
    Bookmark Topic Watch Topic
  • New Topic