My Blog
Articles related to programming, computer science, technology and research.

Java program that displays the number of characters, lines and words in a text file

08/06/2016 Categories: Files. Comments Off on Java program that displays the number of characters, lines and words in a text file

Java program that displays the number of characters, lines and words in a text file. import java.io.*; class FileDemo { public static void main(String args[]) { try { int lines=0,chars=0,words=0; int code=0; FileInputStream fis = new FileInputStream(“sample.txt”); while(fis.available()!=0) { code = fis.read(); if(code!=10) chars++; if(code==32) words++; if(code==13) { lines++; words++; } } System.out.println(“No.of characters = […]

Read the rest of this entry »

Java program to display file information

08/06/2016 Categories: Files. Comments Off on Java program to display file information

Java program that reads a file name from the user and then displays information about whether the file exists, whether the file is readable/writable, the type of file and the length of the file in bytes and display the content using FileInputStream.

Input and output for the above program is as follows: File name: […]

Read the rest of this entry »
Scroll Up