-
August 6th, 2011, 09:57 AM
#1
How to save a file to a chosen directory
Hi, Can anyone teach me how can I save a chosen file to a specific directory. I have used FileDialog to allow users to search the file that they wanted.
import java.awt.Button;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MainClass extends Frame {
FileDialog open;
MainClass() {
super("MainClass");
setSize(200, 200);
open = new FileDialog(this, "Choose a file", FileDialog.LOAD);
open.setDirectory("C:\\");
Button b;
add(b = new Button("Browse...")); // Create and add a Button
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fc.setVisible(true);
String fn = fc.getFile();
if (fn == null)
System.out.println("You cancelled the choice");
else
System.out.println("You chose " + fn);
}
});
}
public static void main(String[] a) {
new MainClass().setVisible(true);
}
}
Please tell me how to save the selected file thank you.
-
August 6th, 2011, 01:33 PM
#2
Re: How to save a file to a chosen directory
how to save the selected file thank you.
What do you mean by "save" the selected file?
Copy its contents to a new location?
If so, you need to ask the user for the name and the location to copy the file to.
And then you must read the contents of the file and write it out to the new file.
Norm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|