Differences

This shows you the differences between two versions of the page.

Link to this comparison view

javalinecount [2014/10/26 01:52] (current)
Line 1: Line 1:
 +===== Java Line Count - returns number of lines in a file =====
 +<code java>
 +import java.io.*;
 +
 +public class LineCount
 +{
 +    public static int lineCount(String fileName) {
 +        File fin = new File(fileName);​
 +        int lines = 0;
 +        if (fin.exists()) {
 +            try {
 +                BufferedReader br = new BufferedReader(new FileReader(fin));​
 +                String oneLine;
 +                while ((oneLine = br.readLine()) != null) {
 +                    lines++;
 +                }
 +                return lines;
 +            }
 +            catch (IOException e) {
 +                System.err.println(e);​
 +            }
 +        }
 +        return 0;
 +    }
 +
 +    public static void main(String args[]) {
 +        if (args.length > 0) {
 +            System.out.println(LineCount.lineCount(args[0]));​
 +        }
 +    }
 +}
 +
 +</​code>​
 +
 +  * [[javainfo|Back to Java]]
  
javalinecount.txt ยท Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0