Results 1 to 2 of 2
  1. #1
    selvin_raj is offline Member
    Join Date
    Jun 2008
    Posts
    5
    Rep Power
    0

    Question Requesting help in copy paste of folder similar to windows.

    Dear All,

    I need help in copy pasting folder similar to windows, that is when I copy and paste a folder repeatedly ; the pasted folder name should be as follows.

    First time: "copy of new folder"
    Second time: "copy of (1) new folder"
    Thrid time: "copy of (2) new folder"


    I have the basic code to copy a folder, I have hard coded "copy of" text before copied folder. Following is the code please help me.


    public Boolean copyConfiguration(String configurationName) throws FileNotFoundException, IOException
    {

    boolean isCopied = false;

    ResourceBundle resourceBundle = null;
    ResourceBundle resourceBundleServer = ResourceBundle.getBundle( Constants.ATTEST_SERVER_PROPERTY_FILE );
    resourceBundle = ResourceBundle.getBundle( Constants.MESSAGES_PROPERTY_FILE, Language.getInstance( ).getLocale( ) );
    String configurationPath = resourceBundleServer.getString("configurationPath" ) + "/data/";
    String originalConfiguration = configurationPath + File.separator + configurationName;
    String ConfigurationTobeCopied = configurationPath + File.separator + File.separator +"copy_of_" +configurationName;
    File newDestination = new File(ConfigurationTobeCopied);
    File sourceConfiguration = new File(originalConfiguration);
    ConfigurationFileFilter tempFileFilter = new ConfigurationFileFilter();
    File[] sourceConfigurationFiles = sourceConfiguration.listFiles();

    FileChannel in = null, out = null;

    try
    {

    if( !newDestination.exists( ) ) // If the configuration does not exists.
    {
    newDestination.mkdirs( );
    }

    for ( int count = 0; count < sourceConfigurationFiles.length; count++ )
    {
    if ( sourceConfigurationFiles[count].isFile( ) )
    {

    if(sourceConfigurationFiles[count].getName().compareToIgnoreCase("file1.xml") == 0)
    {
    in = new FileInputStream( sourceConfigurationFiles[count] ).getChannel( );
    out = new FileOutputStream( newDestination + File.separator + sourceConfigurationFiles[count].getName( ) ).getChannel( );
    long size = in.size();
    MappedByteBuffer buf = in.map(MapMode.READ_ONLY, 0, size);
    out.write( buf );
    }
    else if (sourceConfigurationFiles[count].getName().compareToIgnoreCase("file2.xml") == 0)
    {
    in = new FileInputStream( sourceConfigurationFiles[count] ).getChannel( );
    out = new FileOutputStream( newDestination+File.separator+sourceConfigurationF iles[count].getName( ) ).getChannel( );
    long size = in.size();
    MappedByteBuffer buf = in.map(MapMode.READ_ONLY, 0, size);
    out.write( buf );
    }


    }
    }

    isCopied = true;
    }
    finally
    {
    if ( in != null ) in.close();
    if ( out != null ) out.close();

    }

    return isCopied;
    }

    Regards,
    Selvin
    Last edited by selvin_raj; 06-23-2008 at 06:48 AM.

  2. #2
    selvin_raj is offline Member
    Join Date
    Jun 2008
    Posts
    5
    Rep Power
    0

    Question Is there any one with the solution?

    Is there any one with the solution?

Similar Threads

  1. How can i copy a folder from one place to another..
    By rajeshgubba in forum New To Java
    Replies: 4
    Last Post: 06-14-2008, 02:21 AM
  2. Java Application Interface similar with Windows Themes
    By Heracles Choe in forum AWT / Swing
    Replies: 9
    Last Post: 05-02-2008, 03:47 AM
  3. Replies: 0
    Last Post: 02-06-2008, 03:55 PM
  4. java copy paste cut and undo functions
    By Mr tuition in forum AWT / Swing
    Replies: 1
    Last Post: 12-09-2007, 12:02 AM
  5. How to implement Cut and Paste
    By Jamie in forum AWT / Swing
    Replies: 2
    Last Post: 05-31-2007, 06:15 PM

Posting Permissions

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