Spencer Du

Greenhorn
+ Follow
since Aug 07, 2019
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
2
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Spencer Du

Piet Souris wrote:For instance:



Thank you so much I have a working program now with the required output being shown.
2 weeks ago

Piet Souris wrote:Yes. If you turn that code into a method that returns the nr of lines, then you can make this small addition to your code in the opening post:



Ok so how do i write the whole code for the program?
2 weeks ago

Piet Souris wrote:hi Spencer,

there are some easy ways. The first is to use a Scanner, like:


Alternatively, you can use a Stream, like:

If you don't want the burden of physically loading those files, you could have some statistics about the average length of a line in a file. From that and the size of a file, you can give an estimate of the number of lines. This is not exact, of course.



Hi is there a way to do this without having to add each txt file individually to the code?

Thanks
Spencer
2 weeks ago

Spencer Du wrote:

Tim Moores wrote:Welcome to the Ranch.

A crude measure would be to count the number of newline characters (\n) in the file.

As an aside: why are you using file.toString() instead of file.getName(), as in the line below that?



Ok how do I write the syntax for this?



Can you help me please?
2 weeks ago

Tim Moores wrote:Welcome to the Ranch.

A crude measure would be to count the number of newline characters (\n) in the file.

As an aside: why are you using file.toString() instead of file.getName(), as in the line below that?



Ok how do I write the syntax for this?
2 weeks ago
package examPaper20152016;
Hi I have some code where I print out all the names of txt files from a folder/directory. I now also want to have the number of lines present in each file printed next to each txt file name but I am not sure how to do this. All help much appreciated.



Thanks
Spencer
2 weeks ago