• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

FileDialog.SAVE (urgent please)??

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to have FileDialog which will be displayed when user clicks on a save button.
when the file dialog is displayed the file should be written to seletecd folder.
Can any one show me how to do that?
I will appreciate it!
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by john klucas:
I want to have FileDialog which will be displayed when user clicks on a save button.
when the file dialog is displayed the file should be written to seletecd folder.
Can any one show me how to do that?
I will appreciate it!



I think This Will Solve Your Problem ..Please imtimate me if you need something else
Thanking You
Pradeepta
The Code :
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class SaveFile extends Frame implements ActionListener
{
Button b;
FileDialog fd;
String dir,filename,extention;
byte[] barr=null;
public SaveFile()
{
super("Save File Demo");
setLayout(new FlowLayout());
b=new Button("Open");
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
try
{
if(ae.getActionCommand().equals("Open"))
{
fd=new FileDialog(this,"Open Dialog",FileDialog.LOAD);
fd.show();
dir=fd.getDirectory();
filename=fd.getFile();
System.out.println(dir+" "+filename);
if(dir.length()>0 && filename.length()>0){
b.setLabel("Save");
FileInputStream fis=new FileInputStream(dir+filename);
barr = new byte[fis.available()];
fis.read(barr,0,fis.available());
StringTokenizer stoken=new StringTokenizer(filename,".");
while(stoken.hasMoreTokens())
extention=stoken.nextToken();
fis.close();
}
}
else if(ae.getActionCommand().equals("Save"))
{
if(dir.length()>0 && filename.length()>0){
fd=new FileDialog(this,"Save Dialog",FileDialog.SAVE);
fd.show();
dir=fd.getDirectory();
filename=fd.getFile();
FileOutputStream fos=new FileOutputStream(dir+filename+"."+extention);
fos.write(barr);
fos.close();
b.setLabel("Open");
}
}
}catch(Exception e){System.out.println(e);}
}
public static void main(String[] args)
{
SaveFile sf=new SaveFile();
sf.setSize(400,400);
sf.setVisible(true);
}
}
reply
    Bookmark Topic Watch Topic
  • New Topic