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

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...(8000); oos.writeObject("Ankit"); oos.writeObject("Java Developer
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
Advertisements
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
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
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
Java program to read a text file and write to another file
Java program to read a text file and write to another file - Creating... How to Write to a File in Java without overwriting? Java read.... Our requirement is to read a text file and then write the content of the text
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
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
Java write to file
Java write to file  How to write to a file in Java? Is there any... is the examples: Example program to write to file. File Handling examples in Java... Examples How to read file in Java into byte array All Java tutorials
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. (adsbygoogle = window.adsbygoogle || []).push
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java... to write in the file. For more details and examples related to How to write in File... some data in the file we require some class file, objects and custructor. To open
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... to write to File in Java Program: (adsbygoogle = window.adsbygoogle
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
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 (adsbygoogle = window.adsbygoogle || []).push({});   Hi, Read complete tutorial with example at Read file in java. Thanks (adsbygoogle
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 that is easy to read and learn. Thanks   Hi, (adsbygoogle... = window.adsbygoogle || []).push({}); There is many more examples at Java File
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
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 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 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... = window.adsbygoogle || []).push({}); To write in xml file in java program
how to write append file in Java
how to write append file in Java  How to write append file in Java... existing file should be retained when you are trying to write new contents...({}); For More Details visit this link: How to Append 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...({}); How to use Write To File By Line in Java programs
Java Write to File
Java Write to File In this tutorial you will learn how to write to file in java. Write to a file in java we are required to use some classes of java.io...("This example demonstrates you how to write in a file."); br.close
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
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... in example ?inputStream.close()?. The output of read file line by line in Java... class of Java API is another way to read a file line by line in Java. It used
Java read file line by line - Java Tutorial
; C:\nisha>java FileRead this is a file...C:\nisha>javac ReadFile.java C:\nisha>java ReadFile This is a text file? C:\nisha>
CREATE AND WRITE FILE THREAD JAVA
CREATE AND WRITE FILE THREAD JAVA  Hi guys I was wondering how can I make this program in java with threads. I need to create a file and write in it (i know how to do that) but by listening in some port all the data that is being
read complete file as string java
read complete file as string java  Hi, How I can read read complete file as string java? Thanks   Hi, You can do like this in one line: String fileContent = new String(Files.readAllBytes(Paths.get(fileName
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... java.io.*; /** * This example code shows you how to read file in Java * */ public... to read the character files. This class takes file name as a parameter
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...({}); Example Here is the program to read a file in Java. import java.io.*; public
What is the best way to write to file in Java?
What is the best way to write to file in Java?  I am creating... to write to a text file in Java? Since my program will continuously write the data... the tutorial at Java Write To File - Java Tutorial. Thanks
Write to a file
Write to a file       As we have read about  the BufferedOutputStream class that store the data in an internal buffer and lets you write
read a file
read a file  read a file byte by byte   import java.io.File..._TO_REPLACE_1 public static void main(String[] args) { File file = new File("D://Try.txt"); try { FileInputStream fin = new FileInputStream(file
How to Write to a File in Java
In this Java tutorial, we will demonstrate how to write to a file in Java... to a file from Java program. To write the Java Write To File we will use two... given above and execute it, this will write "Hello Java" into out.txt file
tow method to read and write .
tow method to read and write .  i have two method , frist named "readString" which has no input ,and output b type string ,. second method named "writeString" which accept b as imput and return nothing .........please i want
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... are trying to write in that file by java program like as : (adsbygoogle
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... InputStreamReader(in)); readline() is used to read the next line. Example of Java Read File
How to write in Binary file in Java programming language
How to write in Binary file in Java programming language  I need some help about Java programming. Please explain me "How to write in Binary file in Java programming language
how to write to file from string in Java
me for how to write to file from string in Java. I am beginner in Java...({});   Hi, Are you eager to learn how to write to file from string in java.../writeToFileFromString.shtml Here you will find the how to write to file from string in java
file read
file read  hi i am reaing from a file which has punjabi words. can some one help with me some code
Java Write To File - Java Tutorial
Java Write To File - Java Tutorial Learn how to write to a file from Java... on a FileOutputStream classes to write data to a file from Java program... Tutorial you will learn how to write java program to write to a file. We will use
Read file into byte array java code eample
Read file into byte array java code eample  Hi, I have a project where I have to write for that reads file into byte array. I want a code java code... the code example of the tutorial: Reading binary file into byte array in Java
java - read file line by line in Java
java - read file line by line in Java  Hi, how one can read a text... in Java? Why I can't read a big text file in memory? Thanks... to read file line by line in Java? (adsbygoogle = window.adsbygoogle
How to write file from inputstream in java
How to write file from inputstream in java  Hi, how to write file from inputstream in java program. Plz suggest an example or suggested link... query "How to Write to inputStream in Java". This is good reference website
Java Write To File - Java Tutorial
; write data into new file: ADS_TO_REPLACE_2 out.write(read_the_Buffered_file...For writing data to a file, the class FileWriter and BufferedWriter... of OutputStreamWriter class that is used to write text (as opposed to binary data

Ads