
Not really, the method throws the exceptions... and the jvm will exit upon this. I mean, if something goes wrong, the solution is b0rked no matter what, so it does not matter anyhow (it might lack a bit of style, but that is a different discussion).
we should extend the java version with some try catching too...
Kenny Billiau wrote:
the full perl solution:
#!perl
open IN, "<${ARGS[0]}"; open OUT, ">${ARGS[1]}"; my $n = $ARGS[2];
while (<IN>) { print OUT substr $_,$n; }
And yes .. it's shorter ;)
On Fri, 18 Jul 2008, Michiel Van Bel wrote:
ok, here is the full java code:
class ReduceFile{ public static void main(String[] args) throws Exception{ BufferedReader reader = new BufferedReader(new FileReader(new File(args[0]))); BufferedWriter writer = new BufferedWriter(new FileWriter(new File(args[1]))); int length = Integer.parseInt(args[2]); String s = reader.readLine(); while(s!=null){ writer.write(s.substring(length,s.length())+"\n"); s = reader.readLine(); } reader.close(); writer.close(); } }
Then execute with : "java ReduceFile fileIn fileOut n"
Cannot be simpler... (though i agree that java is quite a verbose language compared to perl)
Michiel
==