|
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 08:48 AM.
|