1 Reply Latest reply: Dec 27, 2013 7:06 AM by shahpartho RSS

    Want code that paste the file on right click in JFilechooser

    9e40c49a-adc4-411d-8bbd-8c8bf63ea532

      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
          shahpartho

          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[]{
                StandardCopyOption.REPLACE_EXISTING,
                StandardCopyOption.COPY_ATTRIBUTES


              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

          Parth