File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes FileDialog.SAVE (urgent please)?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "FileDialog.SAVE (urgent please)??" Watch "FileDialog.SAVE (urgent please)??" New topic
Author

FileDialog.SAVE (urgent please)??

john klucas
Greenhorn

Joined: Jul 31, 2001
Posts: 23
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!
Pradeepta Bhattacharya
Greenhorn

Joined: Sep 07, 2001
Posts: 15
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);
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FileDialog.SAVE (urgent please)??