write a Java program that performs the following task on an input text file.
1. Determine the number of characters
2. Count the number new-lines
3. Identify the number of empty lines.
I have been working on this problem that I saw on the book and the part where I'm stuck on is identifying the number of empty lines. The text file is called "assignment.txt" and it contains the instructions above. This is my code so far:
import java.io.*;
public class Count
{
public void Lines()throws IOException
//counting the lines
{
File f = new File("assignment.txt");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
br.readLine();
LineNumberReader ln = new LineNumberReader(br);
int count = 0;
while (ln.readLine()!=null)
{
count++;
}
System.out.println("No. of lines = " + count);
}
public void Charact()throws IOException
// counting characters
{
File f = new File("assignment.txt");
FileReader fr = new FileReader(f);
new BufferedReader(fr);
long numChar = f.length();
int countChar =0;
while(countChar<numChar)
{
countChar++;
}
System.out.println("No. of characters = " + countChar);
}
public static void main(String args[])throws IOException
{
Count ob1 = new Count();
ob1.Charact();
ob1.Lines();
}
}