To perform character count.
String fPath="D:/MyTextFile.txt";
int fileCharactersCount=Files.readAllBytes(new File(fPath).toPath() ).length;
System.out.println("fileCharactersCount: "+fileCharactersCount);
To perform word count in text or notepad file.
String fPath="D:/MyTextFile.txt";
int fileWordCount=0;
for (String line : Files.readAllLines(new File(fPath).toPath()))
{
line.replace("\t", " ");
fileWordCount+=new StringTokenizer(line, " ").countTokens();
}
System.out.println("fileWordCount: "+fileWordCount);
For more details and notepad related operations use below link.
- Jar file for notepad operation
- Notepad related function create and update.