Home Answers Viewqa Java-Beginners Count characters from text file in Java

 
 


Mika Joeng
Count characters from text file in Java
1 Answer(s)      7 months ago
Posted in : Java Beginners

At the "Count chracters fro mtext file in Java". I tried to run the code, but the error at the line have the directory of the text file ("C:\text.txt"). I use Eclipse to run this code. I copied the text.txt into the same folder of src of the file, and put my directory is ("C:\users\john\study\text.txt"), but its still has error said "the invalid escape sequence " HOw can I fix it? please tell me . Thanks

View Answers

October 5, 2012 at 10:16 AM


Here is a java code that count the occurrence of each character from text file.

import java.io.*;
import java.util.*;

class CountCharactersFromFile {
public static void main(String[] args) throws Exception{
FileInputStream fstream = new FileInputStream("C:\\data.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine="";
String str="";
while ((strLine = br.readLine()) != null) {

str+=strLine;
}
String st=str.replaceAll(" ", "");
char[]third =st.toCharArray();
System.out.println("Character Total");
for(int counter =0;counter<third.length;counter++){
char ch= third[counter];
int count=0;
for ( int i=0; i<third.length; i++){
if (ch==third[i])
count++;
}
boolean flag=false;
for(int j=counter-1;j>=0;j--){
if(ch==third[j])
flag=true;
}
if(!flag){
System.out.println(ch+" "+count);
}
}
}
}









Related Pages:
Count characters from text file in Java
Count characters from text file in Java  At the "Count chracters fro mtext file in Java". I tried to run the code, but the error at the line have... is a java code that count the occurrence of each character from text file. import
Count characters from text file in Java
Count characters from text file Using Java Here we are going to count the occurrence of each character from the text file. For this, we have used the BufferedReader  class to read the specified file. Then we have removed
Count number of characters in a column.
Count number of characters in a column.  I just need you suggestions. Am from Biology Back ground. I just need to find out number of characters in a column i.e, if i have a file with text in this manner ACGT GCTA GCTA i need
Java count characters from file
Java count characters from file In this section, you will learn how to count characters from the file. Description of code: Firstly, we have used FileReader... read the file and count the occurrence of each character of the content
Character from text file - Java Beginners
Character from text file  Write a program that reads characters from a text file. Your program will count how many time each character appear in the text. Assume that the letters are case-sensitive. Example output
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file
Count Characters from the input string Java
Count Characters from the input string of Java In this section, you will learn how to count the occurrence of each character in the string. For this, we have... the string from the console. Firstly we have removed all the spaces between the string
Count number of "*"
Count number of "*"  I have this code to count the number of * from a string entered. but I need to find it from an text file. Any idea? import...:"); String text = bf.readLine(); int count = 0; for (int i = 0; i
Count instances of each word
Count instances of each word  I am working on a Java Project that reads a text file from the command line and outputs an alphabetical listing... going wrong...could anyone help to put me in the right direction? From my text file
count characters
count characters  i have to print the total number of char 'A' in all... sabah sarawak terengganu the output must be count the total number of char... main(String[] args) { int count=0; Scanner input=new Scanner
Java file line count
Java file line count In the section, you will learn how to count the number of lines from the given file. Description of code: Java has provide various... class here, to read  all the lines from the file. You can see in the given
Java Word Count - Word Count Example in Java
Java Word Count - Word Count Example in Java  ... to count the number of lines, number of words and number of characters... some strings and program will count the number of characters and number of words
Java count files in a directory
main(String[] args) { File f = new File("C:/Text"); int count = 0; for (File file : f.listFiles()) { if (file.isFile()) { count...Java count files in a directory In this section, you will learn how to count
Read Lines from text file
Read Lines from text file  Here's a brief desc of what my Java code does .. I'm using BufferedReader to read lines from a text files and split each... read from the text file and displays the output as desired. Unable to read the rest
Reading text from image file - Java Beginners
Reading text from image file  How Read text from image file
Count lines of a particular file
C:\vinod\Math_package>javac NumberOfLine.java C:\vinod\Math_package>java NumberOfLine Getting line number of a paritcular file example! Please enter file name with extension: AddTwoBigNumbers.shtml
stop word removal from text file
stop word removal from text file  i need java source code for stop word removal from a text file
Create text file at client's directory from server.
Create text file at client's directory from server.  Need java code to create text file at client's directory from server..... Please Help
Java count frequency of words in the string
Java count frequency of words in the string. In this tutorial, you will learn how to count the occurrence of each word in the given string. String manipulation forms the basis of many algorithms and utilities such as text analysis
Count Row - JSP-Servlet
(); ResultSet res = st.executeQuery("SELECT COUNT(*) FROM regiform...Count Row  Hello all, Please I need your help on how to desplay... using java servlet and html form. Thanks for your good job!   Hi friend
Java Count word occurrence and export it to excel file
Java Count word occurrence and export it to excel file Here is an example of scanning a text file in a local drive, and count the frequency of each word in the text file or you can say count the number or occurrence of each word
Count repetitions of every word from an input file
Count repetitions of every word from an input file  Hello..i got to know how can i count the repetitions of every word present in a specific input file?For suppose if i have a url log file which have time,url's,ip address etc
convert data from pdf to text file - Java Beginners
convert data from pdf to text file   how to read the data from pdf file and put it into text file(.txt
Java program to generate the total count
would take a text file as an input and scans through it to generate the output. For Ex. : If the text file contains the following information: There is/are 3.... END OF TEXT FILE The output required is: Oranges:8 Apples:14 Bananas:0
Java search word from text file
Java search word from text file In this tutorial, you will learn how to search a word from text file and display data related to that word. Here, we have created a text file student.txt which consists of id, name and marks of few
Java count words from file
Java count words from file In this section, you will learn how to determine the number of words present in the file. Explanation: Java has provides several... from the file. You can see in the given example, we have initialized a counter
characters java - Java Beginners
.(REmember that the alphabet contains 52 characters if you count uppercase... " +str + " has " +j +" characters"); System.out.println(""); } int count(char...characters java  HELLO MAM AND SIR I ASK YOUR HELP HOPE YOU GONNA
Programming: Count Words - Dialog
Java NotesProgramming: Count Words - Dialog Description Write a program which counts the number of words in text the user enters. Assume that a word.... Examples Because of our definition of "word" is any characters separated from others
Count Vowels
Count Vowels   Read a string from the user, your program counts the number of vowels in the text and have it report a sum of each vowel found as well as the number of spaces. Make it in two classes
Read specific column data from text file in java
Read specific column data from text file in java  My question is if my text file contain 15 columns and i want read specific column data from that text file then what code i should do
To Count The Elements in a XML File
To Count The Elements in a XML File   ... Xerces Description of program: This program takes a file name from the console...; Here is the Java File: CountNodes.java
Java Read Lines from Text File and Output in Reverse order to a Different Text File
Java Read Lines from Text File and Output in Reverse order to a Different Text File  I need to read a file that was selected by the user using... to another text file. When that is done the output values of that file need
Search word from text file using Java
How to Search word from text file using Java In this section, we are going to search a word from the text file. For this, we have created a swing button... from the text file. Here is the code: import java.io.*; import
Programming: Count Words - Dialog
Java NotesProgramming: Count Words - Dialog Description Write a program which counts the number of words in text the user enters. Assume that a word..." is any characters separated from others by a blank, "123" is a word, as well
Java Write To File From String
Java Write To File From String In this tutorial you will learn how to write to file from string. Write to file from string using java at first we will have... by you with containing the text that you are trying to write in that file by java
How to make a list from file text in J2ME - Java Beginners
How to make a list from file text in J2ME  I was trying to make a method that read file from text and make a list of it, I have tried ReadHelpText...) { } return null; } kamus.txt file contains: iconSebuah lambang kecil berupa gambar
Count the character in java
Count the character in java  Write a java program to count....   Count characters by implementing thread import java.util.*; class...[]=st.toCharArray(); int count=ch.length; System.out.println("Total Characters
Read from file java
Read from file java  How to Read from file java? What is the best method for a text file having a size of 10GB. Since i have to process the file one line at a time so tell me the very best method. Thank you
How to Remove Repeated Characters from the String?
How to Remove Repeated Characters from the String?  Hi, I trying to develop an application which will remove the repeated characters from... the example of how to remove repeated characters from the string. Please visit
Remove duplicate characters from the string
Remove duplicate characters from the string In this tutorial, you will learn how to remove duplicate characters from the string. Java has provide several.... Here we are going to remove duplicate characters from the string
Remove Repeated Characters from the String
Remove Repeated Characters from the String In this we are going to remove repeated characters from the string. For this, we have allowed the user to enter the string. The class BufferedReader reads the string from the console. Then we
text file
at the start of the program from a seperate external text file.Thank you! mport...text file  Hi can you help me I have to modify the program below so that all the data held in it is stored in an external text file.So there should
count in java - Java Beginners
, count of frmale is 20. what's code in java to select count from database where...(); ResultSet rs=st.executeQuery("SELECT count(id_sales) from...count in java  Hello javamania.... i want to ask something like
Limiting characters - JSP-Servlet
Limiting characters  Iam doing a jsp project. In this i have a text area which should accept not more than 300 characters. I solved...+v and paste option from edit menu. Anyone send me the solution. Please
Reading a text file in java
in java.io.* package for reading and writing to a file in Java. To learn more about reading text file in Java see the tutorial Read File in Java. Thanks...Reading a text file in java  What is the code for Reading a text file
System Independent Newline Characters
Java NotesSystem Independent Newline Characters There are three different.... Windows. Windows programs often process a '\n' separated text file correctly... Java program is running on from the system properties. It is essential to do
Removing Line Termination Characters from a String
Removing Line Termination Characters from a String... of with program code which reads the string or text of a text file which... symbol where the new line character was present in the string or text
Escaping Special Characters in a Pattern
characters from the given string or text. Here, you can learn the way... special characters in the given string or text. This program finds special... characters in the given string or text. Code Description: Pattern.compile("
how to create text file from jsp and provide downlode option
how to create text file from jsp and provide downlode option  HI... file so that pepole can downlode that text file or may be some other file formate this my jsp page <%@ page language="java" contentType="text/html; charset
Delete specific lines from text in Java
Delete specific lines from text in Java  Hi, beginning in java, i'm trying to delete specific line from a text file. Ex: i want to delete data... number that i want to delete. how could it be possible with java. thanks a lot

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.