Link to home
Start Free TrialLog in
Avatar of binaryjim
binaryjim

asked on

Is there a File.copyTo() ?

I need to copy a source file (which as an added difficulty is a jar file) to a certain destination.

I can move it with File.renameTo() but what I actually need is to copy it eg a File.copyTo() method.

I wrote my own but it did not work even tho' the file sizes are the same, I get a "class not found" when I try to use the copied jar file. I assume that's java security for you, so I think I need a "java approved" method of copying a jar file.

Any ideas?
Jim
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Can you show your code?
ASKER CERTIFIED SOLUTION
Avatar of schybert
schybert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of schybert
schybert

Ooops, might want to make that a public method :-)
Avatar of binaryjim

ASKER

Thanks, must've been my sloppy code. I did think tho' that you were not allowed to re-create/tamper with jar files. How the JVM could tell I'd no idea.
So why does File not have a File.copyTo() method then?
So you're not interested why yours didn't work then?
Not really, more interested to know why there is no File.copyTo() method. The code was a bit dirty, tho' it re-created the file in the correct place and was the correct size:
  while(true){
     int nextByte = inpstream.read();
     if (nextByte==-1)
       break;
     outstream.write(nextByte);
 }
Not sure why there is no copy method.

There's nothing to stop that code you posted working as it stands.

>>it re-created the file in the correct place and was the correct size

Then your code worked already.
Ok, thanks for that :-)