source: release-kits/lirk3/ant-scripts/tasks/antelope/src/ise/antelope/tasks/typedefs/file/FileLineCount.java@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 1.1 KB
Line 
1package ise.antelope.tasks.typedefs.file;
2
3import java.io.*;
4import org.apache.tools.ant.BuildException;
5
6/**
7 * Copyright 2003
8 *
9 * @version $Revision: 1.2 $
10 */
11public class FileLineCount implements FileOp {
12
13 /**
14 * Description of the Method
15 *
16 * @param f a file
17 * @return the number of lines in the file
18 */
19 public String execute(File f) {
20 if (f == null)
21 throw new IllegalArgumentException("file cannot be null");
22 //System.out.println(f);
23 LineNumberReader lnr = null;
24 try {
25 lnr = new LineNumberReader(new FileReader(f));
26 String line = lnr.readLine();
27 while(line != null) {
28 line = lnr.readLine();
29 }
30 return String.valueOf(lnr.getLineNumber());
31 }
32 catch(Exception e) {
33 throw new BuildException(e.getMessage());
34 }
35 finally {
36 try {
37 if (lnr != null)
38 lnr.close();
39 }
40 catch(Exception e) {
41 // ignored
42 }
43 }
44
45 }
46}
47
48
Note: See TracBrowser for help on using the repository browser.