Character from text file

Character from text file

View Answers

October 21, 2009 at 4:41 PM

Hi Friend,

Try the following code:

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);
}
}
}
}

Thanks









Related Tutorials/Questions & Answers:
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
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
Advertisements
Read Lines from text file
read from the text file and displays the output as desired. Unable to read the rest...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
How to delete a character from a file in java - Java Beginners
How to delete a character from a file in java  I'm not gettting how to remove a character from a file in java....could any one help me out?? ... to read each and every character from file and check for the required string
Count characters from text file in Java
is a java code that count the occurrence of each character from text file. import...Count characters from text file in Java  At the "Count chracters fro... the directory of the text file ("C:\text.txt"). I use Eclipse to run this code. I
Reading text from image file - Java Beginners
Reading text from image file  How Read text from image file
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
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data
Program to read the text from a file and display it on a JFrame.
Program to read the text from a file and display it on a JFrame.  import javax.swing.*; import java.io.*; import java.lang.*; import java.awt.... with this is only the last character is been displayed on the tabbed frame(i.e
Read Text file from Javascript - JSP-Servlet
Read Text file from Javascript  plz send the code How to Retrieve the data from .txt file thru Javascript? And how to find the perticular words in that file
binary search tree from text file
binary search tree from text file  How so I go about constructing a binary search tree from a text file, which has letters and numbers, which must be sorted and printed in ascending order. E.g. Text file contents 3 apples pears
how to match the key word from a text file
how to match the key word from a text file  p>Hi all, I have the code to match the key word and from the text. I have input like this reader.txt... want to get the value from the called file and get the result. String regex1
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
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
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 dump 10lakh lines from a text file to a mysql table
To dump 10lakh lines from a text file to a mysql table  I need to dump a text file datas -100000 lines into a mysql table.i'm able to dump only 152000 lines only
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
Write records into text file from database
Write records into text file from database You have already learnt how to insert records from text file to database. But here we are going to retrieve records from database and store the data into the text file. For this purpose, we have
create login page using data from text file
create login page using data from text file  I want to create login page using data store in textfile(data submit from regiter page to textfile) using jsp and servlet. Thanks
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
How to extract a specific line from a text file? - IoC
How to extract a specific line from a text file?  Hi all, i'm trying to write a code that return a specific line from a text file. so my first...° 100 to 120 for example. My Text file contain numbers and words. How i have
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... data base..........i need output of this page in text file and also downlode
Removing character from a string in sql.
Removing character from a string in sql.  How to remove or replace character from a string
Removing duplicate white spaces from a text file
Removing duplicate white spaces from a text file  ... duplicate white spaces from a specific text file. In this section a program is given... spaces from the given text file. This program reads the file line-by-line for search
Removing character from a string in sql.
Removing character from a string in sql.  Removing special characters from a string in sql
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
text file
text file  Hello can I modify the program below so that all the numerical data is stored in an external text file,that is the data contained in the array list.Thank you! mport java.util.*; import java.text.*; import
Get Character from String
Get Character from String     ... of character and retrieve elements from that character array one by one... toCharArray() to convert string to character array. 3. Retrieve character from
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... in which I have created a new text file using the File constructor
Java Remove a character from string
Java Remove a character from string In this tutorial, you will learn how to remove a character from the string. There are several methods for examining... to remove a particular character from the string. In the given example, we have
Text From Your Clipboard?
Text From Your Clipboard?  Text From Your Clipboard
Writing to File in Java
Writing to File in Java Writing any character or text in Java file is possible... are used for writing Character files and Text Files respectively while another class... file) This is the simplest example of the class used for writing character file
Convert Text File to PDF file
Convert Text File to PDF file  Here is the way how to covert your Text file to PDF File, public class TextFileToPDF { private static void...(inLine); System.out.println("Text is inserted into pdf file
Reading a text file in java
Reading a text file in java  What is the code for Reading a text file... 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
Convert Text File to PDF file
Convert Text File to PDF file  import java.io.BufferedReader; import...); System.out.println("Text is inserted into pdf file"); document.close... FileReader( Input File)); String inLine = null
Sorting text file
Sorting text file  Hello friends, i'm writing search page for my local website. i'm storing all file list in text file. And also adding a value... according to begin value. Text File having list like this: 5| 3| can anyone
Read Specific Line from file Using Java
Read Specific Line from file Using Java Here we are going to read a specific line from the text file. For this we have created a for loop to read lines 1 to 10 from the text file. If the loop reached fifth line, the br.readLine() method
inserting text into text file using java application
inserting text into text file using java application  Hi, I want to insert a text or string into a text file using java application
how to update the text file?
how to update the text file?  if my text file contains a string and integer in each line say,: aaa 200 bbb 500 ccc 400 i need a java code to update the integer value if my input String matches with the string in file. please
uploading a text file into a database
uploading a text file into a database  how to upload a text file... { static File file; public static void main(String[] args) throws Exception { JLabel label=new JLabel("Choose File
PHP get character from String
PHP Get Character From String To get sub string from a String we can use substr() method. Structure of this method is :ADS_TO_REPLACE_1 string substr (string $var, int $initial [, int $len]  ) In the above example we want
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program
Read text File
Read text File  Hi,How can I get line and keep in a String in Java
how to update the text file?
how to update the text file?  my textfile with name list.txt: Rice... i want to update the quantity in my text file, if the item i entered matches...=new float[n1]; for(int i=0;i File file ; FileReader fr=null
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program  
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program  
Read File from specified path in Java
reads a text file from specified path in Java. We will give complete path... is a complete example of the program that reads a text file from the disk path and print...How to read a file from a specified path in Java? After learning so many

Ads