ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Otto Perdeck" <otto.perd...@xs4all.nl>
Subject Re: concat-two-files task
Date Sun, 10 Mar 2002 20:08:08 GMT
Or, as a last resort, simply call a Java program to do this. It really should be written as
a task, of course, but for lack of time and conceptual simplicity, we use it now as just an
external Java program. Call it with redirecting the output of the "java" task to the destination
file.


The trivial Java code would be something like


// Mini-utility to cat a number of files. Just like
// Unix "cat", but this works on any box.
//
// java Cat file1 [file2 ...]

import java.io.*;

public class Cat
{
    public static void main(String[] args)
        throws Exception
    {
        for (int i=0; i<args.length; i++) {
            File f = new File(args[i]);
            System.out.println();
            if (f.exists()) {
                BufferedReader r = new BufferedReader(new FileReader(f));
                String line;
                do {
                    line = r.readLine();
                    if (line != null) {
                        System.out.println(line);
                    }
                } while (line != null);
                r.close();
            } else {
                System.out.println("# No file \"" + args[i] + "\"");
            }
        }
    }
}


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message