aspose file tools*
The moose likes Beginning Java and the fly likes Lines of Code Counter in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Lines of Code Counter in servlet" Watch "Lines of Code Counter in servlet" New topic
Author

Lines of Code Counter in servlet

Nash Reddy
Greenhorn

Joined: Mar 17, 2010
Posts: 1
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

Joined: Jan 10, 2002
Posts: 60979
    
  65

Whether you do this in a Servlet or not is moot, so I've moved this to the Beginner java forum for any discussion.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10246
    
    8

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?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
wood burning stoves
 
subject: Lines of Code Counter in servlet