• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

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);
}
}
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic