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

Hybrid View

  1. #1
    Join Date
    Aug 2011
    Posts
    3

    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.

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    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
  •  





Click Here to Expand Forum to Full Width

Featured