Java: Read File, Calculate Number of Lines, Words And Characters, Print to Screen And To File

  1. Home
  2. Homework Library
  3. Computer Science
  4. Java Programming
  5. Java: Read File, Calculate Number of Lines, Words And Characters, Print to Screen And To File

QuestionQuestion

Write a program that asks the user for a file name (or path).
Your program should then open that specific file. (Assume the file will be .txt).
Your program should then calculate the following information based on the specified text file:
1. The total number of words in the file
2. The number of lines in the file
3. The number of characters in the file (not including spaces)
Once the information is calculated, print the data to the screen and also to a new file called results.txt.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;



/**
*
* @author
*/
public class Assignment {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
       // TODO code application logic here
       Scanner console = new Scanner(System.in);
       System.out.print("Enter file name (or path): ");
       String name = console.nextLine();
       int line = 0;
       int word = 0;
       int character = 0;
       String next;...
$15.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats