Copying a file in Java

darobin on 2003-02-24T15:24:41

If you need some extra ammo to convince your Java-coding friends(?) that they have strayed far from common sense, ask them how to copy a file in Java (look at the two given options). No, java.io.File has rename and delete, but no copy.


LOL

mir on 2003-02-24T15:57:33

That Java thing is really kewl, here is what the link let too:

HTTP Status 500 - Internal Server Error

type Exception report

message Internal Server Error

description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.

exception

java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav a:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at com.ee.servlet.HandleJspServlet.invoke(HandleJspServlet.java:114)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNex t(StandardPipeline.java:641)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
&nb sp;   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
&nbs p;   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNex t(StandardPipeline.java:643)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java :170)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNex t(StandardPipeline.java:641)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNex t(StandardPipeline.java:641)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
&nb sp;   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174 )
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNex t(StandardPipeline.java:643)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
&nb sp;   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
    at org.apache.ajp.tomcat4.Ajp13Processor.process(Ajp13Processor.java:458)
    at org.apache.ajp.tomcat4.Ajp13Processor.run(Ajp13Processor.java:551)
    at java.lang.Thread.run(Thread.java:536)
Caused by: com.TeamNoggin.util.DBManager$InvalidDBException: com.TeamNoggin.util.OracleDataSourceManager: error calling releaseConcreteConnection - ORA-00020: maximum number of processes (610) exceeded

    at com.ee.util.SessionUtil.createSession(SessionUtil.java:97)
    ... 23 more

Apache Tomcat/4.1.18-LE-jdk14

Re:LOL

darobin on 2003-02-24T16:08:15

Hahaha, oh man, this is sooo much fun. Pity you can't see the code though, it was really horrible. I managed to sanitize it down to 30 lines for my needs, but it's still rather kludgy to say the least.

Re:LOL

exeunt on 2003-02-24T16:38:42

Google is your friend. Cached version

Also, for fun, look at the java code for the Copy task in Ant.

Ditto...

Purdy on 2003-02-24T16:06:53

I also got the error message. I believe, though, you can write a system call to copy the file, but that would become system-dependent (cp vs. COPY).

Jason

Re:Ditto...

darobin on 2003-02-24T16:17:58

Yeah, you can System.exec(), but that's just wrong...

Discussion on Perlmonks

danboo on 2003-02-24T18:15:41

Something similar came up on perlmonks a while ago. I posted some java solutions that were as fast as perl, and not nearly as verbose as the solutions given on experts-exchange. They require JDK 1.4 though.

http://www.perlmonks.org/index.pl?node_id=148355

cheers,

  - danboo