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 $1 if you
register a new account!

Assisting Tutor

Related Homework Solutions

Java Project For Consulting Company
Homework Solution
$50.00
Java
Programming
Computer Science
Consulting Company
Inventory
Interfaces
Products
Lookup
Classes
Libraries
Queries
Finance
Employees
Management
OOP
Function
Methods
Loops
Conditions
Parking Problem in Java
Homework Solution
$30.00
Java
Programming
Codes
Classes
Computer Science
Parking
OOP
Car Model
License Number
Owner Name
Strings
Integers
Statements
Input
Output
Constructor
Public Methods
Functions
Interactive Command-Line Game in Java
Homework Solution
$50.00
Java
Programming
Coding
Game Development
Computer Science
Zork
Colossal Cave Adventure
Command Line
Maps
2D Grid
Win
Lose
Classes
OOP
Methods
Fields
String Values
Integers
Statements
ArrayList Fraction Objects in Java
Homework Solution
$15.00
Java
Programming
Computer Science
Coding
Arrays
Fractions
Numerator
Denominator
Decimal Values
Sorted List
Algorithms
Loops
Variables
Statements
Conditions
Multiplication Table in Java
Homework Solution
$40.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Rows
Columns
Input
Output
Integers
Strings
Multiplication
Tables
Operations
Conditions
Get help from a qualified tutor
Live Chats