Problem copy file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sateesht
    New Member
    • Apr 2007
    • 41

    #16
    Hi,

    Try with the below code :

    File f = new File(Source Directory);
    File dir=new File(Destinatio n Directory);

    boolean success = file.renameTo(n ew File(dir, file.getName()) );
    if (success) {
    System.out.prin tln("File moved");
    }else {
    System.out.prin tln("File Not Moved");
    }


    Cheers,
    Sateesh.

    Comment

    • sateesht
      New Member
      • Apr 2007
      • 41

      #17
      Hi,

      Try with the below code :

      File file = new File(Source Directory);
      File dir=new File(Destinatio n Directory);

      boolean success = file.renameTo(n ew File(dir, file.getName()) );
      if (success) {
      System.out.prin tln("File moved");
      }else {
      System.out.prin tln("File Not Moved");
      }


      Cheers,
      Sateesh.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #18
        Originally posted by sateesht
        Hi,

        Try with the below code :

        File file = new File(Source Directory);
        File dir=new File(Destinatio n Directory);

        boolean success = file.renameTo(n ew File(dir, file.getName()) );
        if (success) {
        System.out.prin tln("File moved");
        }else {
        System.out.prin tln("File Not Moved");
        }


        Cheers,
        Sateesh.
        Surely you know that all code should be posted using code tags.

        Comment

        • eyeofsoul
          New Member
          • Sep 2007
          • 31

          #19
          Code:
                public void actionPerformed(ActionEvent e){
                   
                  String x = "\\";
                  //Handle open button action.
                  if (e.getSource() == openButton) {            
                      int returnVal = fc.showOpenDialog(PilihFail.this);
                      if (returnVal == JFileChooser.APPROVE_OPTION) {
                          File file = fc.getSelectedFile();
                          //This is where a real application would open the file.
                         jtfOpen.setText(file.getAbsolutePath());
                        
                      } else {
            
                      }
                  } 
                  //Handle save button action.
                  else if (e.getSource() == saveButton) {
                      int returnVal2 = fc2.showSaveDialog(PilihFail.this); 
                      fc2.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                      
                      if (returnVal2 == JFileChooser.APPROVE_OPTION) {
                          File file2 = fc2.getSelectedFile();
                      
                        jtfSave.setText(file2.getParent()+x); 
                      } 
                     else {
                      }
                  }
                  
                  else if (e.getSource() == Copy) {
                     new Salin2().start();
                  }
              }
          hello..i still didnt manage to get the file name to be combine to the directory if i click saveButton.how do i recall the file from the openButton?!plz ..

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #20
            Did you manage to get the file's name without the path using the File.getName() method?

            Comment

            • eyeofsoul
              New Member
              • Sep 2007
              • 31

              #21
              no..i have read through http://java.sun.com/j2se/1.4.2/docs/...a/io/File.html
              but seems i cannot understand pretty well.

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #22
                Originally posted by eyeofsoul
                no..i have read through http://java.sun.com/j2se/1.4.2/docs/...a/io/File.html
                but seems i cannot understand pretty well.
                If you call getName on your source File, you get the name of the file you want to copy. You really should be understanding this since you wrote this program yourself didn't you?

                Comment

                • eyeofsoul
                  New Member
                  • Sep 2007
                  • 31

                  #23
                  actually..i make the code by reading examples..such as how to copy file..how to implements listeners..then i combine it as one..

                  Comment

                  Working...