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



Home Answers Viewqa Java-Beginners Java file read write operation
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Dhirendra
Java file read write operation
1 Answer(s)      a year and 9 months ago
Posted in : Java Beginners


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 to the other class.Suggestion please


Advertisement
View Answers

January 4, 2013 at 11:48 AM


hi Dhirendra, here I am giving a sample code

code for writing object

    oos = new ObjectOutputStream(fos);

                 oos.writeObject("Ankit");
                 oos.writeObject("Content Writer");
                 oos.writeInt(8000);

                 oos.writeObject("Ankit");
                 oos.writeObject("Java Developer");
                 oos.writeInt(20000);

                System.out.println();
                System.out.println("objects written to the stream successfully");

2. code for reading object

    ois = new ObjectInputStream(fis);

                 String sh = (String) ois.readObject();
                 String cw = (String) ois.readObject();
                 int      sal = ois.readInt();

                 String am = (String) ois.readObject();
                 String cw1 = (String) ois.readObject();
                 int      sal1 = ois.readInt();
                 System.out.println();
                 System.out.println("Name \t"+"Department \t"+"Salary");
                 System.out.println(sh+"\t"+cw+"\t"+sal);
                 System.out.println(am+"\t"+cw1+"\t"+sal1);

for complete tutorial you can follow this link

Java ObjectOutputStream ObjectInputStream
http://roseindia.net/java/example/java/io/objectinputoutputstream.shtml


Related Tutorials/Questions & Answers:
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..."); oos.writeInt(8000); oos.writeObject("Ankit"); oos.writeObject("Java
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
Advertisements
To read & write a excel file using the core java
To read & write a excel file using the core java  Hai, I'm new to JavaProgram.But now i need java program to read & write a excel file so, can anyone help me to learn the above mentioned topic(link for the portion
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
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?  write a program in java to read a text file and write the output to an excel file using filereader and filewriter
read and write a file using javascript
read and write a file using javascript  How to read and write a file using javascript
write a progam for bubble sort using file read nd write?
write a progam for bubble sort using file read nd write?  hi, please give the code
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 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 write to file
Java write to file  How to write to a file in Java? Is there any... to a text file. Here is the examples: Example program to write to file. File Handling examples in Java Java Input/Output Examples How to read file in Java
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
read/write to Windows Registry using Java
read/write to Windows Registry using Java  read/write to Windows Registry using Java
Java read binary file
Java read binary file  I want Java read binary file example code... at Reading binary file into byte array in Java. Thanks   Hi, There is many more examples at Java File - Learn how to handle files in Java with Examples
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java. Please suggest and give example of this program. thanks
Read Write
Read Write  Hi; How can I read certain line of say 10 text files and write to one text file   Java Read Multiple Files and store the data into another text file The given code reads all the text files of the directory
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file  ...) { //read from start original file String arry[] = sCurrentLine.split...{ String sCurrentLine; // Groped file name (Suresh.txt
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file  ...) { //read from start original file String arry[] = sCurrentLine.split...{ String sCurrentLine; // Groped file name (Suresh.txt
is there any possibelities fast read and write file large data file
is there any possibelities fast read and write file large data file  ...) { //read from start original file String arry[] = sCurrentLine.split...{ String sCurrentLine; // Groped file name (Suresh.txt
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java... bufferedWriter object to write in the file. For more details and examples related to How to write in File of Java Program
How to Write to file in Java?
How to Write to file in Java?  How to Write to file in Java Program?   Hi, For writing a file in Java, we need some classes from Java.IO... the Examples of How to write to File in Java Program: WriteToFileExample.java import
simple code to write an read and write the login detail to a xml file using javascript ( username and password )
simple code to write an read and write the login detail to a xml file using javascript ( username and password )  pls can nyone give me a code to write and read the login details (username and password )into a xml file using
How to Read file line by line in Java program
by line in Java. But there are various ways that can help read a larger file...()?. The output of read file line by line in Java is printed on console... of Java API is another way to read a file line by line in Java. It used
Java read lines from file
Java read lines from file  Any code example related to Java read... of reading file line by line in Java. Can any one share me the code for reading java file line by line. My file is very big around 6.5GB so it's not possible
Read File in Java
Read File in Java This tutorial shows you how to read file in Java. Example... shows you how to read file in Java * */ public class ReadFileExample { public... java.io.FileReader is used to read the character files. This class takes file name
How to Read a File in Java
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... can be very inefficient. Example Here is the program to read a file in Java
How to write file by line in Java
How to write file by line in Java  How to write file by line in Java   Hi, For Write to a file by line using java programming language we... in a new line. How to use Write To File By Line in Java programs
How to write into CSV file in Java
How to write into CSV file in Java  How to write into CSV file in Java   Hi, To create Comma separated value(CSV) file is very simple... passed the file name to write into a stream characters. Then we use the FileWriter
Java read file line by line - Java Tutorial
:\nisha>java FileRead this is a file C...C:\nisha>javac ReadFile.java C:\nisha>java ReadFile This is a text file? C:\nisha>
How to write to xml file in Java?
How to write to xml file in Java?  Hi Friends, Can anyone help me how to write in xml file in Java programming. Please fill free to give example or reference website for getting example.   Hi, To write in xml file
How to Write To File BufferedWriter in Java
How to Write To File BufferedWriter in Java  how to write to file bufferedwriter in Java   In Java there are 2 types of class files used in Java.io package i.e. FileWriter and BufferedWriter file. In this section we
how to write append file in Java
how to write append file in Java  How to write append file in Java   Hi, For append in the test new file or Appending a text earlier existing file should be retained when you are trying to write new contents
Advertisements
 

 

 

DMCA.com