• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

problem in copying the directory

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from java program iam trying to copy a directory which contain subdirectories and other files to other directory.but is isnot creating the directory in that location
Runtime r = Runtime.getRuntime();
System.out.println("before xcopy");
Process p = r.exec("cmd /c start xcopy d:/trinadh d:/surya/trinadh");
System.out.println("after executing xcopy");
iam trying to copy the directory trinadh into surya directory
what is the problem with this programm.plese tell me the solution for this
 
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Trinadh..

Try using


In place of -->Process p = r.exec("cmd /c start xcopy d:/trinadh d:/surya/trinadh");

Because I just tried only the xcopy part of your code on the commandline and it gace an error on invalid switch...may be thats why its not giving you the desired output..

Be sure to put 2 backward slashes in the 1st line( otherwise it will take it as any escape character)...

Try it..
Ramy..
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you stepping outside of the VM instead of using the core API?
Take a look at java.io.File.
 
trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Process p = r.exec("cmd /c start xcopy d:\\trinadh d:\\surya\\trinadh");
when iam trying to copy the files are copying but the subdirectories anf the files in that subdirectories are not copying.please tell me the solution for this
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried running the command at a DOS prompt to make sure it works. I think you'll find you need to specify some options. Type xcopy /? to get a list of options.
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to copy the whole directory with java.io.File
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a sample code for copying the files from a directory.
Check this link
 
pvsr rao
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i tried with that it is copying the empty direcory but not all its subdirectories.iam sending my program also
import java.io.*;
public class copy
{

private void copyFile(File src, File dst) throws IOException
{
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);

// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ( (len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();

}

public int copyDirectory(File srcDir, File dstDir) throws IOException
{
if (srcDir.isDirectory())
{
if (!dstDir.exists())
{
dstDir.mkdir();
}

String[] children = srcDir.list();
int c= children.length;
System.out.println(c);
for (int i = 0; i < children.length; i++) {
copyDirectory(new File(srcDir, children[i]),
new File(dstDir, children[i]));
}
}
else {
// This method is implemented in e1071 Copying a File
copyFile(srcDir, dstDir);
}
return 1;
};


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

copy c = new copy();
c.copyDirectory(new File("d:/raj/sub "),new File("d:/sub"));
c.copyFile(new File("d:/raj/sub/auth.html"),new File("d:/sub/auth.html")) ;
}
}

pleaase help me how to resolve this problem
 
So you made a portal in time and started grabbing people. This tiny ad thinks that's rude:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic