JAVA-Record-06)AIM: Write a Java program that displays the number of characters, lines and words in a text file.
06)AIM:
Write a Java program that displays the number of characters, lines and words in a text file.
Algorithm
Step 1: Start,
Step 2: Initialize charCount, wordCount and lineCount to 0.
int charCount = 0;
int wordCount = 0;
int lineCount = 0;
Step 3: Read all the lines of the text file one by one into currentLine using FileInputStream method.
FileInputStream Fis = new FileInputStream("");
Step 4: Update Chars Count ,Lines Count, Words Count each time we read the line into current Line.
code = fis.read();
if(code!=10)
chars++;
if(code==32)
words++;
if(code==13)
{
lines++;
words++;
}
Step 5: Print " Chars ",
Step 6: Print " Lines ",
Step 7: Print " Words ",
Step 8: Stop.
Code:06-01
Save: FileDemo.java
Code:06-02
Save:sample.txt
Output:01
Comments
Post a Comment