Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Interview-Questions Read the file Contents

Have Programming Question? Ask it here!
 
 
 


Dineshram
Read the file Contents
1 Answer(s)      2 years and 2 months ago
Posted in : Java Interview Questions


Ravi Raj,Vijay45Shankar,234
Guna,345,Meet me,654,Cow

Read file contents and Print the no.of words and Numbers./p>

Thanks, Dinesh Ram


Advertisement
View Answers

May 29, 2012 at 4:45 PM


The given code read the file content and print the no.of words and Numbers.

import java.io.*;
class  CountWordsAndNumberFromFile{
    public static void main(String[] args) throws Exception
    {
        BufferedReader br=new BufferedReader(new FileReader(new File("c:/A.txt")));
        String str="",st="";
        while((str=br.readLine())!=null){
          st+=str+" ";
        }
        String s=st.replace(","," ");
        String array[]=s.split(" ");
        int word=0,num=0;
        for(int i=0;i<array.length;i++){
            if (array[i].matches("((-|\\+)?[0-9]+(\\.[0-9]+)?)+")) {  
            num++;
        } else {  
            word++;  
        }
        }
        System.out.println("Number of numbers: "+num);
        System.out.println("Number of words: "+word);
    }
}


Related Tutorials/Questions & Answers:
Read the file Contents
Read the file Contents  Ravi Raj,Vijay45Shankar,234 Guna,345,Meet me,654,Cow Read file contents and Print the no.of words and Numbers./p> Thanks, Dinesh Ram   The given code read the file content and print
Java read file contents into byte array
Java read file contents into byte array  Hello share the code of java read file contents into byte array with me. It's urgent. Thanks   Hi, This is simple process if you use the InputStream class. Read example
Advertisements
How to read the contents in a file which is of input type file
How to read the contents in a file which is of input type file  I have a jsp page wherein i have to passs the file as input and read the contentsn... //In this servlet page i have tried to read the contents of a file in doPost method. I have used
How to read excel contents when uploaded
How to read excel contents when uploaded  I am working on a project where the user uploads his excel file. Jsp page must read the excel contents... file must be read and the contents must be displayed on the screen. How
PHP file_get_contents() Function
PHP file_get_contents() Function  Hi, How do i read the content of file using PHP program? So kindly provide any example or online help reference for filegetcontents() Function in PHP. Please feel free to suggest. Thanks
The PHP file_get_contents() function , file_get_contents php
The PHP file_get_contents() Function Function reads the content of the whole file to a string. This function is the best way to read the contents... is supported by the servers. So, the use of file_get_contents() will make your program
read a file
read a file  read a file byte by byte   import java.io.File... static void main(String[] args) { File file = new File("D://Try.txt"); try { FileInputStream fin = new FileInputStream(file); byte
file read
file read  hi i am reaing from a file which has punjabi words. can some one help with me some code
The PHP file_put_contents() function , file_put_contents php
Learn how to use file_put_contents() function in PHP Example of the PHP file_put_contents() function Description Syntax of file_put_contents() PHP file_put_contents(file_name,data_to_file,[file_mode,[file_context]]) It writes
Viewing contents of a JAR File
Viewing contents of a JAR File       This section shows you how you can read the content of jar file... the contents of the jar file without extracting it. You can easily understand about
Read file in java
Read file in java  Hi, How to Read file in java? Thanks   Hi, Read complete tutorial with example at Read file in java. Thanks
java read file
java read file  Hello i need some help... i want to read an MS Excel file in java so how to read that file
Read and write file
Read and write file  HI, How to read and write file from Java program? Thanks   Hi, See the following tutorials: Java Write To File Read File Thanks
Read external file in PHP
Read external file in PHP  How to read external files in PHP in particular time duration and save that file with the latest date. How is it possible? Please explain with an example. Thanks
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
Java read binary file
Java read binary file  I want Java read binary file example code that is easy to read and learn. Thanks   Hi, Please see the code at Reading binary file into byte array in Java. Thanks   Hi, There is many
Read Video File
Read Video File  how to read a video file, after that i want to encrypt and decrypt it. please help me and if u can send me some hint or source code on swarit.it@gmail.com Thanks & Regards Swarit Agarwal
print only Form Fillup Contents through Text File - Java Beginners
print only Form Fillup Contents through Text File   Hello Sir ,I have... contents which is filled by employee,How i can Print it,and also i want print it with word means when i click on print then contents which is filled
How to browse excel file and stored the contents into the database using jsp/servlet?
How to browse excel file and stored the contents into the database using jsp/servlet?  Hi.. I want to browse excel file and stored the file data into the My-sql database using jsp/servlet
How to Read a File in Java
use to read the contents of a file. Its two most commonly used constructors...How to Read a File in Java? In this section we are going to know, How to read a file in Java. We have to follow three step to read a File. First get
Read text File
Read text File  Hi,How can I get line and keep in a String in Java
read restricted pdf file
read restricted pdf file  i have restricted file. package Encryption; import java.io.*; import java.util.*; import com.lowagie.text.*; import com.lowagie.text.pdf.*; public class EncryptionWithCertificate { public
read restricted pdf file
read restricted pdf file  i have restricted file. package Encryption; import java.io.*; import java.util.*; import com.lowagie.text.*; import com.lowagie.text.pdf.*; public class EncryptionWithCertificate
read doc and docx file in javascript
read doc and docx file in javascript  How i read doc and docx file in javascript
read and write a file using javascript
read and write a file using javascript  How to read and write a file using javascript
J2ME Read Multiple File - MobileApplications
J2ME Read Multiple File  Hello I have read a topic "J2ME Read File", but that example is specify for a single file, but what if i want read more file one after the other just like Books. And an example will i appreciate thanks
Read file zip in J2ME - MobileApplications
Read file zip in J2ME  I would like to read file.zip in J2ME,I don't know how to extract it. Please help me
Read Property file From Jmeter
Read Property file From Jmeter  Hi, I am running web driver script from Jmeter, but while reading property file I am getting "File Not Find Exception". Please tell me how to read ".properties" file from Jmeter
Java read file in memory
Java read file in memory In this section, you will learn how to read a file... and then read the file... for the  file, and then call map( ) to produce a MappedByteBuffer, which
Java Read CSV file
Java Read CSV file In this tutorial, you will learn how to read csv file. CSV (Comma Separated Value) is a common type of data file which can be exported... opened a file data.csv  and created a BufferedReader object to read
How To Read File In Java
there must be a file which contents can be read so, I have created a file named... of java.io package. To read the file contents used read() method...How To Read File In Java In this section we will discuss about about how data
Java read lines from file
to read the whole file in one go. So, in my case reading file line by line is only...Java read lines from file  Any code example related to Java read lines from file? In my project there is requirement of reading the file line by line
Java read properties file
Java read properties file In this section, you will learn how to read properties file. Description of code: There are different tools to access different... can read any properties file. Output: Name: RoseIndia
Listing Contents of a ZIP File
Listing Contents of a ZIP File     ... to read the zip file entries. Here is the code of the program... of a zip file through the java code. Following program helps you for the appropriate
Read PDF file
Read PDF file Java provides itext api to perform read and write operations with pdf file. Here we are going to read a pdf file. For this, we have used PDFReader class. The data is first converted into bytes and then with the use
how to read this xml file - XML
how to read this xml file  i want to read this xml file using java... read i have tried lot more , but i am not able to read this xml file... name=client menu=client action=read user employee add
J2ME Read File
J2ME Read File       In this J2ME application, we are going to read the specified file. This example shows you how to read the data of the specified file. To implement this type
Read file into String
Read file into String In this section, you will learn how to read a file... data from the file using it's read() method. This data is then stored... we have used FileReader and BufferedReader class to read the file into memory
Upload and insert the file contents - Java Server Faces Questions
Upload and insert the file contents  I want to browse and upload 2... please post the sample of CSV file. I will develop the example for you. Thanks   Hi here is the sample csv file data. Duct,1,Civils - General
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
Java file read write operation
Java file read write operation  how to read and write the data from text file.Suppose i have text file with 4 fields name ,roll no ,marks1,marks2 with more than 20 records......i need to store these value in object and pass
Read a zip file.
file and direct the zipread command to read it through while loop. The zip_entry_read command will read one byte at a time. when it reads all the contents...)){  $content = zip_entry_read($zipcontent,1024); echo "Contents : "
Java read latest file
Java read latest file Java provides IO package to perform file operations. Here we are going to read the last modified file. For this, we have used..., read that particular file. Here is the code: import java.io.*; import
Java read text file
hasNextLine() method to read the contents of a file line by line. Scanner...In the section we are discussing about how to read file line by line. Here we... a text file one line at a time. It can also be used to read large text files
C file read example
C file read example       This section demonstrates you to read a line from the file. You can see in the given example, we prompt the user to enter the name of the file to read
Java read file
There are many ways to read a file in Java. DataInputStream class is used to read text File line by line. BufferedReader is also used to read a file in Java... line. Example of Java Read File: package FileHandling; import
objective c read file line by line
objective c read file line by line  Please explain how to read files in Objective C line by line
Java read entire file into byte array
Java read entire file into byte array  Where is the example of Java read entire file into byte array on your website? Thanks   Hi, Its simple you can use insputStream.read(bytes); method of InputStream class. Read
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
read excel file from Java - Java Beginners
read excel file from Java  How we read excel file data with the help of java?  Hi friend, For read more information on Java POI visit to : http://www.roseindia.net/java/poi/ Thanks
Advertisements
 

 

 

DMCA.com