A couple things. I don't see the looping that you're talking about in the java versions. The java version from the original poster provides 2 methods for copying, and both read the whole contents of the file into an array and then write that array out to a new file. So the overall idea *is* the same: read the entire first file into memory, write that memory to a second file.
Also, you do realize that the java "version" is actually 2 different methods? So it's not really as long as it appears. Additionally, condensing the JDK 1.4 version I gave below down to some hideuos anonymous objects it gets pretty short. Not on par with the perl version, but hey, that's one of perl's features.
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class X2 {
public static void main (String [] args) throws Exception {
FileChannel in = new FileInputStream(args[0]).getChannel();
new FileOutputStream(args[1]).getChannel().write(in.map(
FileChannel.MapMode.READ_ONLY, 0, in.size()));
}
}
Cheers,
- danboo
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.