Objective

Practice reading text files and working with String data.

Implement a java program that uses the JFileChooser dialog to let the user specify a file on the system. The program should then open and read the file line by line. The program should then print a summary report of the file to the console (screen). The summary report should contain the following:

  • The name of the file the user chose to process
  • Number of lines in the file
  • Number of words in the file
  • Number of characters in the file

Suggested process

Open the file after the user specifies it with JFileChooser. Read each line one at a time keeping track of how many lines you read. As you read each line, count how many words there are. (A simple way to do this is to count the number of spaces separating the words. N spaces suggests that there are N + 1 words on the line assuming no doubled spaces. You can also use the split function to return an array of the words and the length of the array is how many words there are.) Finally, as you read each line use the String length property to count how many characters are in the line and keep track of the total.

Get a screenshot that shows the JFileChooser running.

Get a screenshot that shows your output stats for a successful program run.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.