Reading Files and Print 1 Answer(s) 3 years and a month ago
Posted in : Java Beginners
Hey Guys,
I'm a beginner to java and I wanna write this program. I wanna create files including information of the students in my class. Each file contains a student's name, e-mail, school, hobby. There are almost 30 files.
When I want to find students whose school is "School A" , what I want to do is, I want my program to read all the files and find the Particular name "School A" and print all contents in the file(s).
I give a the user to input. So that user may input any name or a phrace, after that what my program is gonna do is read all the file and if it finds any content that is equal to the user input its gonna print the entire file content.
In a case where more than one student are from the same school it should print all the information about all those students. I think I'm clear.. Please help me with this..
View Answers
April 29, 2010 at 10:54 AM
Hi Friend,
Try the following code:
import java.io.*; import java.util.*;
public class Files{ public static void main(String[]args) throws Exception{ Scanner input=new Scanner(System.in); System.out.println("Enter school Name"); String sch = input.nextLine(); String fname[]={"s1.txt","s2.txt","s3.txt","s4.txt"}; File file = new File("data.txt"); FileWriter fstream = new FileWriter(file,true); BufferedWriter out = new BufferedWriter(fstream);
for (int i=0;i<fname.length;i++){ File f = new File(fname[i]); try { BufferedReader freader = new BufferedReader(new FileReader(f)); String s; while ((s = freader.readLine()) != null) { String[] st = s.split(" "); String name = st[0]; String email = st[1]; String school = st[2]; String hobby = st[3]; if (school.equals(sch)) { System.out.println(name+" "+email+" "+hobby); out.write(name+" "+email+" "+school+" "+hobby); out.newLine(); } } freader.close(); } catch (Exception e) { } } out.close();
} }
In the above code, we have read only four files.Similarly,you can read all the files.
Thanks
Related Pages:
Reading Files and Print - Java Beginners ReadingFiles and Print Hey Guys,
I'm a beginner to java and I wanna write this program. I wanna create files including information.... There are almost 30 files.
When I want to find students whose school is "School
Reading and writting multiple files Reading and writting multiple files how can i read and write say two different files at the same time using threads
Reading files in Java Readingfiles in Java I have to make a program in my project....
Please provide me the example code for reading big text file in Java. What do you suggest for Readingfiles in Java?
Thanks
Reading and Writing files - Java Beginners Reading and Writing files Hello,
please help me to Develop a simple Java application that, when run, Welcomes the users and tells them the name... to investigate writing to files a little (can be also done using Properties
How to print differences of two text files
How to print differences of two text files I have the code to compare 2 different text files, however How can I put the difference of 2 text files in other file or print the difrference in the console??
Thanks
How to print list of files in client system
How to print list of files in client system have some list of files in server.i just want to print that files in client machine with out opening the file.i give the option for user like printall.if user click printall prints
reading multiple files from a directory and writing them into a single file reading multiple files from a directory and writing them into a single file... this:
/*this program reads multiple files
* from a single directory. */
package elite.tech.com... File(inpath);
File files[];
files = Folder.listFiles
Reading from remote files using PHP,Ubuntu and Windows machine. Reading from remote files using PHP,Ubuntu and Windows machine. Hi,
Great work you doing here and I totally love the look and feel of the new site... on a windows machine within the same network. After reading from it, the script
Writing and Reading A File
Writing and Reading A File Hello, I've been trying to learn writing and reading data from file for our assignment, but just stuck on how to proceed...:
http://www.roseindia.net/tutorial/java/core/files/insertfiledataToJTable.html
Reading Text file and storing in map Reading Text file and storing in map Hi
I have multiple text files. I want to read thoses files and store those records in map.
Map will be of "LinkedHashMap<String, Map<String, String>>" type.
Please let me know
document reading in java - Java Beginners
document reading in java Hi Dipak,
Can you tell me how to read pdf files in to java.i want convert pdf file in xml format through java coding.can you please help me? Hi Friend,
Try the following code
print
print How to print JFrame All Componant?
Please visit the following link:
http://www.roseindia.net/java/example/java/swing/Print.shtml
Print
into the stream and, as opposed to print() method, gets you to the new line after the text
List files recursively in linux
List files recursively in linux Hi,
How to List files recursively in linux? I want to list all the .php file.
Thanks
Hi,
You can use following command:
find . -name *.php -print
Thanks
initialise array by reading from file - Java Beginners
initialise array by reading from file Hello, I wnat to know how i would initialise an array by reading a text file, which contains a simple pattern...
while ((strLine = br.readLine()) != null) {
// Print the content
Compare 2 files
to compare these files and print the diffrence by comparing the report name...Compare 2 files I would like to compare 2 files in Java. please send me the code snipt for this scenario:
File1
Reading duplicate keys from .properties file - Development process Reading duplicate keys from .properties file Hi,
I am reading a .properties file using a basic java program.Though the .properties file... the duplicate keys and print it on console.
It is urgent requirement,please reply
Error in reading Excel data using jsp
Error in reading Excel data using jsp ERROR while executing bellow... and POI library files are there in respective folders.
the printStackTrce... convert it and display as a spreadsheet. HSSF deals with files written in Excel
Reading binary file into byte array in Java
Example code of reading binary file into byte array in Java
This example shows...(String[] args)
{
System.out.println("Reading binary file into byte array... = new String(bytes);
//Print the byte data into string format
How to Print a Stack Trace Message
How to Print a Stack Trace Message
Debugging of Java program requires a lot of efforts. You can use the log
files to log the messages into it. Some times you have to print the detailed
error message on the console
files
files write a java program to calculate the time taken to read a given number of files. file names should be given at command line.
Hello Friend,
Try the following code:
import java.io.*;
import java.util.*;
class
Java error reading from file
Java error reading from file
Java error reading file...
reading from file. For this we have a class error reading from file. Inside
FORM Tag Correctly for Uploading Files.
for Uploading Files?
<?php
print("<html><form action=file...FORM Tag Correctly for Uploading Files. How To Write the FORM Tag Correctly for Uploading Files?
Hi friends,
When you clicks the submit
Reply to the mail(import files error)
Reply to the mail(import files error) Hi!
Thank you. That error has... as
org.hibernate.MappingException: Error reading resource: contact.hbm.xml...-to-the-mail(import-files-error).html
Thanks
Reading RDF file in Java Reading RDF file in Java
As you know that The Resource Description Framework is
used... you how to read the RDF files in Java. In the next example you will be
learning
Read File in Java
is
used to handle the files in Java. In this example we will use following classes
of java.io package for reading file:
FileReader
The class java.io.FileReader is used to read the
character files. This class takes file name
Uploading Multiple Files Using Jsp
Uploading Multiple Files Using Jsp
 ... to understand how you can upload multiple files by using the Jsp.
We should avoid... a file.
In
this example we are going to tell you how we can upload multiple files
Uploading the multiple files
. For uploading the multiple files at a time, first create a table as per required number of files to be uploaded. After creating a table, the files should be posted...;
<HTML>
<HEAD>
<TITLE> Multiple Files Upload </TITLE>
combine two pdf files
combine two pdf files
In this program we are going to tell you how you can
read a pdf file... the logic of our program.
First of all create a PdfReader object for
reading the pdf
File I/O - Text Files
Java NotesFile I/O - Text Files
Java can read several types of information from files: binary,
Java objects, text, zipped files, etc. One of the most common
problems is reading lines of text.
Example: Copy one file to another
svg file reading and display
svg file reading and display i want a sample program for reading and displaying the content of a svg file
print a form of * print a form of * *
***
*****
*******
*********
*******
*****
***
*
Post the format properly
print the newline print the newline Why doesn?t the following code print the newline properly?
<?php $str = ?Hello, there.\nHow are you?\nThanks for visiting.?; print $str; ?>
Hi friends,
Inside the single quotes \n (newline
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
Print the document Print the document I tried to print web page.I am using the below...()
{
var printWindow = window.open('test', 'Print Window', 'height=600,width...;Print Window</title>');
printWindow.document.write('</head>
Print the document Print the document I tried to print web page.I am using the below...()
{
var printWindow = window.open('test', 'Print Window', 'height=600,width...;Print Window</title>');
printWindow.document.write('</head>
Concatenate pdf files using command argument
Concatenate pdf files using command argument
 ... pdf files
into a destination pdf files through java program. The all data...;Make or Download the source code of program.
Put the source code and pdf files
Print a statement Print a statement hello
what would we output for this statement
System.out.println ("5"+"A" + 3);
hello
output will be
5A3
date print
date print how can i print the date in jsp page in the following formate month-date-year.
(example. march 8 2012
date print
date print how can i print the date in jsp page in the following formate month-date-year.
(example. march 8 2012
print the sequence print the sequence how can I write the code by using for loop to produce this following statement: 10,9,8,7,6,5,4,3,2,1,buzz!
please, help me