Monday, April 30, 2018

Count the characters in a file or size of a file !!

Using File:
  1. import java.io.File;

  2. public class CountCharInFile {
  3. public static void main(String[] args) throws Exception {
  4. File file = new File("D:\\data.txt");
  5. int fileDataLen = (int) file.length();
  6. System.out.println(fileDataLen);
  7. }
  8. }
Output: 
241

data.txt file:
Hi guys !!
This is Ishaan from India.
and I'm reading the data from a text file line by line using BufferedReader.
Isn't it interesting !! to read the data from a file line by line 
irrespective of amount of data that a file is having.

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...