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

SOFTWARE

Unit 2: Foundations of Ownership, Security Related Concepts in Blockchain

Unit-1 Foundations of Software Systems and Blockchain

6)what are the various service of internet and protocols ICT-unit-1

digital marketing ppt-u1

Unit-III: Cascading Style Sheets (CSS) - HTML

Unit-V: Image Manipulations, Audio and Video & Introduction to JavaScript

Unit-II: HTML Coding Standards & Elements

HTML Degree Unit-1

1) Information and Communication Technology ICT-unit-1