Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jdavidb (1361)

jdavidb
  (email not shown publicly)
http://voiceofjohn.blogspot.com/

J. David Blackstone has a Bachelor of Science in Computer Science and Engineering and nine years of experience at a wireless telecommunications company, where he learned Perl and never looked back. J. David has an advantage in that he works really hard, he has a passion for writing good software, and he knows many of the world's best Perl programmers.

Journal of jdavidb (1361)

Wednesday March 05, 2008
04:32 PM

Java gravel of the day: We're in outer space: copying files

[ #35845 ]

Sure you can copy files in Java! It's easy! All you have to do is write a routine to read the contents of one file and write it to another file!

What do you mean, there should be a library routine to do this? What do you mean, you want to portably take advantage of whatever OS facilities exist to do this?

Is there something about "copying files in Java is easy" that doesn't make sense to you?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • My question for Java developers is always the same: can you, without looking at the docs, write the code to open a file, read the first line from the file (delimited by a newline) and print said line? The answer is invariably "no, but ...".

    The counter-argument is that since they don't need to do this very often, there's no need to optimize this. When you're working in an "enterprise" environment, you're not constantly opening and reading files. Just to prove this point, I ran this on our codebase here

    • If you do need it, you stick it in a library. Something like:

      String line = FileUtil.slurpLines( path | file )[0];
      Or if you want it from the classpath, not just a file path:

      String line = new Resource( classpath-ref ).slurpLines()[0];
      File handling is one of my Java interview questions :-)