Are you wanting just a commandline command?wc -l myfile.txt (if you are using Unix/Linux) or do you want to use something in java.io.* package or similar? [ November 13, 2003: Message edited by: James Swan ]

Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133

posted Nov 13, 2003 13:07:00

0

Something in a java.io package, something that I would be able to write into my program, not a command line command. Sorry that I didn't clarify [ November 13, 2003: Message edited by: Brandi Love ]

do you need it before you do anything else? you can always read the file one line at a time, and keep a counter... I've never heard of anything that would do what you seem to be asking for, but i'm not willing to say there absolutly is not... how's that for not answering the question???

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133

posted Nov 13, 2003 13:20:00

0

how would I do that? With a while loop, or perhaps a for loop? I need this for a program that serches for a string within some text in a text file, and when it is found gives the location of the line, and column in which the text is located. [ November 13, 2003: Message edited by: Brandi Love ]

James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403

posted Nov 13, 2003 14:10:00

0

enjoy

James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403

posted Nov 13, 2003 14:46:00

0

I need this for a program that serches for a string within some text in a text file, and when it is found gives the location of the line, and column in which the text is located.

In that case you could also look into using java.io.LineNumberReader (which is a subclass of BufferedReader). A basic algorithm would be: - read each line of the file into a String - compare String against criteria (String.indexOf("my_criteria")) - if a match, record line number from LineNumberReader.getLineNumber(), and record position of match in String (indexOf)