CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2011

    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() {
    setSize(200, 200);

    open = new FileDialog(this, "Choose a file", FileDialog.LOAD);

    Button b;
    add(b = new Button("Browse...")); // Create and add a Button
    b.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    String fn = fc.getFile();
    if (fn == null)
    System.out.println("You cancelled the choice");
    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.

  2. #2
    Join Date
    Jun 1999
    Eastern Florida

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.