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

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...