I'm not seeing the output from my class now (I know this is a
simple/stupid thing on my part), what am I doing wrong:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

public class LineCounter extends Task
{
        public String filename;
        public void Execute() throws BuildException
        {
                LineCounter lc = new LineCounter();
                log("about to call countlines");
                log(filename+ " contains " +
lc.countLines(this.filename) +" lines.");
        }
        public void setFilename(String filename)
        {
                System.out.println("we are about to parse ->"+filename);
                this.filename= filename;
        }
        public int countLines(String file)
        {
                ArrayList integlist = new ArrayList();
                try 
                {
                        BufferedReader br = new BufferedReader(new
FileReader(new File(file)));
                        String line;
                        while((line = br.readLine())!=null)
                        {
                                integlist.add(line);
                        }
                        System.out.println(integlist.size());
                        br.close();
                }
                catch (Exception e) 
                {
                        e.printStackTrace();
                        System.exit(-1);
                }
                return integlist.size();
        }

}

-----Original Message-----
From: Rich Wagner [mailto:[EMAIL PROTECTED] 
Sent: Thursday, May 11, 2006 5:18 PM
To: Ant Users List
Subject: Re: Counting lines in a file


> Is there any good way to count how many lines in a file there is?

You could also write a simple, custom Task to do this; see the online 
Ant manual for guidance...

-- Rich Wagner


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to