|
-
copy String array of files to the destination directory and rename it
Hi all, could anyone please help me with the following code.
I am calling the class "filesMove" from my main class. I am passing 3 parameters:
1. filenames - String array of filenames
2. dstfile - destination directory, I need to copy my String array of filenames to here
3. rename- this is the String to which I want to rename the files copied to dstfile. My "main.java" code is:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
JFileChooser chooser=new JFileChooser();
chooser.setCurrentDirectory(curfile);
chooser.setMultiSelectionEnabled(true);
int state=chooser.showOpenDialog(null);
File[] files=chooser.getSelectedFiles();
String[] filenames=getFilenames(files);
File dstfile=new File("C:\\temp\\fontsInstallation");
String rename=jTextField1.getText();
filesMove fm=new filesMove();
fm.copyDirectory(filenames,dstfile,rename);
}
File curfile=new File("D:\\fonts\\");
private String[] getFilenames(File[] files)
{
String[] filenames=null;
String sub=null;
int numFiles=files.length;
if(files.length>0)
{
filenames=new String[numFiles];
for(int i=0; i<numFiles;i++)
{
filenames[i]=files[i].getPath();
}
}
return filenames;
}
====================================================================================
my "filesMove.java" code is:
public class filesMove
{
static String code="";
public filesMove()
{
}
void copyDirectory(String[] filenames, File dstfile, String rename)
{
for(int i=0;i<filenames.length;i++)
{
System.out.println("filenames[i]:"+filenames[i]);
}
System.out.println("dstfile:"+dstfile);
System.out.println("rename:"+rename);
}
}
for instance my source directory contains these many files:
xyz.tfm
xyz.PFM
xyz.PFB
abc.tfm
abc.PFM
abc.PFB
I will be selecting only some files, so from the above code "filenames" will be fetching only these files. My program is working fine till here:
abc.tfm
abc.PFM
abc.PFB
Now I need to copy these files to "dstfile" directory:
abc.tfm
abc.PFM
abc.PFB
and rename it to:
pmnr.tfm
pmnr.PFM
pmnr.PFB
Thanks in advance
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks