Counting the number of characters is important because almost all the text boxes that rely on user input have certain limit on the number of characters that can be inserted. For example, the character limit on a Facebook post is 63, 206 characters. Whereas, for a tweet on Twitter the character limit is 140 characters and the character limit is 80 per post for Snapchat.
Determining character limits become crucial when the tweet and Facebook post updates are being done through api’s.
Note: This program would not run on online compilers. Please make a txt file on your system and give its path to run this program on your system.
Total word count = 5 Total number of sentences = 3 Total number of characters = 21 Number of paragraphs = 2 Total number of whitespaces = 7
In-built functions used
- File(String pathname): java.io.File: Creates a new File instance by converting the given pathname string into an abstract pathname.
public File(String pathname) Parameters: pathname - A pathname string
- FileInputStream(File file): java.io.FileInputStream: Creates a FileInputStream by opening a connection to an actual file, the file named by the File object file in the file system.
public FileInputStream(File file) throws FileNotFoundException Parameters: file - the file to be opened for reading. Throws: FileNotFoundException - if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading. SecurityException - if a security manager exists and its checkRead method denies read access to the file.
- InputStreamReader(InputStream in): java.io.InputStreamReader: Creates an InputStreamReader that uses the default charset.
public InputStreamReader(InputStream in) Parameters: in - An InputStream
- BufferedReader(Reader in): java.io.BufferedReader: Creates a buffering character-input stream that uses a default-sized input buffer.
public BufferedReader(Reader in) Parameters: in - A Reader
This article is contributed by Mayank Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Adding Paragraphs as Text to a PDF using Java
- Java program to delete duplicate lines in text file
- Java streams counting() method with examples
- Java 8 | Collectors counting() with Examples
- Swap corner words and reverse middle characters
- Using Above Below Primitive to Test Whether Two Lines Intersect in Java
- Different ways of Reading a text file in Java
- Java program to delete certain text from a file
- How to draw Horizontal and Vertical lines in an Android App using XML
- Different Ways to Copy Content From One File to Another File in Java
- Print number of words, vowels and frequency of each character
- File handling in Java using FileWriter and FileReader
- Remove duplicate words from Sentence using Regular Expression
- Reverse words in a given String in Java
- Count of words ending at the given suffix in Java
- Java program to print Even length words in a String
- Java Program to Find Duplicate Words in a Regular Expression
- Print characters and their frequencies in order of occurrence using a LinkedHashMap in Java
- Different Ways to Generate String by using Characters and Numbers in Java
- Copying file using FileStreams in Java
Improved By : UmeshAgrawal