Home Answers Viewqa Java-Beginners Java file read write operation

 
 


Dhirendra
Java file read write operation
1 Answer(s)      4 months and 17 days 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

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 Pages:
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
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 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
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
how to write and read text for javaME
how to write and read text for javaME  Hi. I have tried ur read/write coding but why i didnt get the o/p just like urs. do i have to add anything from the library? i want to type multiple line on text file then, read it from
read and write a file using javascript
read and write a file using javascript  How to read and write a file using javascript
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
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
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
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
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 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
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
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 for reading file into byte. Just let's know the best code. Thanks   
What is the best way to write to file in Java?
;Read the tutorial at Java Write To File - Java Tutorial. Thanks...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
Java Read File Line by Line - Java Tutorial
Tutorial you will learn how to write java program to read file line by line. We will use the DataInputStream class to Read text File Line by Line. Class... Java Read File Line by Line - Java Tutorial
Write Text into File
Write Text into File      ... this example we are initialize string to write into file. We are creating file... "write.txt". We are using FileWriter class to read 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
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
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>
Java Write To File - Java Tutorial
an internal FileOutputStream to write bytes to the specified file... the file into specified directory. Following code  write data into new file:  out.write(read_the_Buffered_file_name); Following code creates
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
Java Write To File From FileInputStream
Java Write To File From FileInputStream In this tutorial you will learn how to write to file from FileInputStream. Write to file from FileInputStream in java... input bytes from a file or can say it reads the streams of bytes. And to write
How to read big file line by line in java?
Learn how to write a program in java for reading big text file line by line... to read the big file in your java program. For example you have to process some... to read character files easily in Java program. Constructor takes file name
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
How to make a file read-only in java
How to make a file read-only in java A read-only file is any file... a file read-only by using file.setReadOnly() method of File class. After using this method, you will not be able to write or edit into the file.  Here
Java Read File Line By Line, Video Tutorial of Java Read File Line By Line
Video Tutorial and example for the most searched topic "Java Read File... a program in Java programming language to read a text file line by line. The "Java Read File Line by line" is most searched topics by the Java developers
Date operation - JDBC
); } } ------------------------------------------ Read for more information. http://www.roseindia.net/java/ Thanks
Insert Operation - WebSevices
problem : Some points remmeber : 1.Create a file "home.jsp" having a button...(); } } %> Name Email   For read
Read text File
Read text File  Hi,How can I get line and keep in a String in Java
Read data again - Java Beginners
want this read to DB d00001;Operation;Finance;Finance Head;Kantor Pusat...;Operation;Finance;Finance Officer;Kantor Pusat; My question is:how to read... = DriverManager.getConnection(url+db,"root","root"); //Read File Line By Line
Read file from the Nth line
Read file from the Nth line Java provides several classes and methods to manipulate file. A file reading, is a common operation. Usually a file is to be read from top to bottom but here we are going  to read a file content from
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
write xml file with jsp useBean - JSP-Servlet
write xml file with jsp useBean  how to write into xml files with jsp... allows our application to obtain a Java XML parser. DocumentBuilderFactory... an org.w3c.dom.Document from XML. Save the xml file at bin file of C:\apache-tomat-5.5.23\bin
How to read the data in text file seperated by by ',' in java using IO Operations
How to read the data in text file seperated by by ',' in java using IO Operations  in Text file data like raju 45,56,67 ramu 46,65,78 raji 34,23,56 this is the student marks in text file.this data read and calculate
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
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 read 100 text files from a folder or directory and write the data into a single file.using java programming?
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?  i have multiple(app..100) text... the files and write them into a single file..the target file should have the 1st
Read data again - Java Beginners
","root","suprax"); //Read File Line By Line while ((strLine = br.readLine..."); //Read File Line By Line while ((strLine = br.readLine()) != null...Read data again  OK my problem some like my first question.First i
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
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 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
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... the above code, you can read any properties file. Output
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.