1 Reply Latest reply on Dec 27, 2013 1:06 PM by shahpartho

    Want code that paste the file on right click in JFilechooser


      I want to paste particular file from location to location by using JFilechooser. What I mean is when I open JFilechooser it have one paste option that will paste the file to that location using right click on JFilchooser.


      Please help me for the same.

        • 1. Re: Want code that paste the file on right click in JFilechooser

          Hi ,


          First let me understand your query. You are basically trying to develop an application where in you have copied a file from a certain location and wish to paste it in another and choose this new location through file chooser?


          If this is the issue why not try the following.


          1. Copy the file path into a String Variable.

          2. Choose a location using a filechooser and store the location in another string variable.


          Here is how the code should somewhat look like


          import java.io.IOException;
          import java.nio.file.*;

          public final class whtevercopyclass {

          /*Choose this String from a source file using file chooser*/
            String src_location;

          /*choose this string for destination from file chooser */
            String dest_location;

            public static void main(String[] args) throws IOException

              Path source = Paths.get(src_location);
              Path destination = Paths.get(dest_location);

                CopyOption[] fileoptions = new CopyOption[]{

              Files.copy(source,destination ,fileoptions);



          I am sure u can improvise/filter out any errors in the  code...and also if u absolutely want a copy paste right click functionality u can add a actionlistener in the JFileChooser such that i will read the location into the destination String variable using right click.


          Let me know this helps !!


          Happy Holidays