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 charCountwordCount 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

Popular posts from this blog

digital marketing ppt-u1

SOFTWARE

cn lab

Computer Operations and Performing - D L Unit-1-1

DBMS Degree Lab Records

DS-Record-mca-04) write a program for evaluating a given postfix expression using stack.

Java unit-1 history , C++ vs Java , java environment

Access the Internet to Browse Infromation & E-Mail Operation- D L Unit-2-1

java program structure,java Tokens, keywords,

OAT-Record-01) Visiting card