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

Question

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 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;...

This is only a preview of the solution. Please use the purchase button to see the entire solution

$15.00

or free if you
register a new account!

Assisting Tutor

Related Homework Solutions

Get help from a qualified tutor
Live Chats