File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lines of Code Counter in servlet

 
Nash Reddy
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to take a java file as an input to a servlet program and implement LOCcounter() function, to count th LOC of the program, ignoring blankslines and comments. Im not going anywhere, please hlp me
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether you do this in a Servlet or not is moot, so I've moved this to the Beginner java forum for any discussion.
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Avinash,
Welcome to the Ranch.

Since we do not hand out ready made code here at the Ranch, I will share some pseudo code with you.
1) Open a stream to the. For this you can either use BufferedReader or Scanner
2) Read one line at a time
3) Increment the counter
4) When you finish reading the file, the counter will tell you the number of lines.

This is basic stuff. You need to build logic for identifying if the read line is empty and if the read line was part of some comment.
You have also failed to take into consideration the package statement and import statements. If you ignore them, your code is going to be flawed.

What have you got so far and where are you stuck?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic