-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileDemo.java
More file actions
31 lines (30 loc) · 788 Bytes
/
FileDemo.java
File metadata and controls
31 lines (30 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.io.*;
class FileDemo{
public static void main(String args[]){
try{
int lines = 0, chars = 0, words = 0, 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 =" + chars);
system.out.println("No.of.Words" + (words + 1));
system.out.println("No.of.Lines" + (lines + 1));
fis.close();
}
catch(FileNotFoundException e){
system.out.println("Cannot find the Specified file..");
}
catch(IOException i){
system.out.println("Cannot read file...");
}
}
}