ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "EJ Ciramella" <ejcirame...@upromise.com>
Subject RE: Counting lines in a file
Date Thu, 11 May 2006 22:52:32 GMT
Nevermind - change Execute to execute and everything is well.... 

-----Original Message-----
From: EJ Ciramella 
Sent: Thursday, May 11, 2006 6:42 PM
To: 'Ant Users List'
Subject: RE: Counting lines in a file

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:rich.wagner@savaje.com] 
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: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message