Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How to read the amounts of word from a file?

$
0
0
Take a .txt file for example.

For the homework question we have to make a program that takes the name of a file as a parameter and returns an integer, which contains the number of words in that file.
Here's what I've got so far

public static int wordAmount(String file)throws IOException
				{
					int x=0;
        
					
			
			return x; 
				}
               public static void main(String args[]) throws IOException
	{
               //add/find .txt file can call word wordAmount method
        }
        
        


I think I've got the plan right, I just don't know how to add the .txt file, assign it to the method, and for the method to print how many lines there are.

Any help please? thank you!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>