-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileWordCount1.java
More file actions
58 lines (37 loc) · 1.53 KB
/
fileWordCount1.java
File metadata and controls
58 lines (37 loc) · 1.53 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.*;
class fileWordCount1
{
public static void main(String[] args)
{
BufferedReader reader = null;
int charCount = 0;
int wordCount = 0;
int lineCount = 0;
try
{
reader = new BufferedReader(new FileReader("myownfile1.txt"));
String currentLine = reader.readLine();
while (currentLine != null)
{
lineCount++;
String[] words = currentLine.split(" ");
wordCount = wordCount + words.length;
for (String word : words)
{
charCount = charCount + word.length();
}
currentLine = reader.readLine();
}
System.out.println("Number Of Characters In A File : "+charCount);
System.out.println("Number Of Lines In A File : "+wordCount);
System.out.println("Number Of Words In A File : "+lineCount);
}
catch (IOException e)
{
System.out.println("Something Just Went Wrong!!!!!!!!!!!");
}
}
}