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
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
Can you show your code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ooops, might want to make that a public method :-)
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 why does File not have a File.copyTo() method then?
So you're not interested why yours didn't work then?
ASKER
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);
}
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.
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.
ASKER
Ok, thanks for that :-)