Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
Not able to perform the file io
Aniket Harode
Greenhorn
Posts: 11
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
here is my code for the serializable objects
package com.practice; import java.io.Serializable; import jdk.internal.org.objectweb.asm.commons.SerialVersionUIDAdder; public class Animal implements Serializable{ public static final long SerialVersionUIDAdder=1L; int size; String name; char type; public Animal(int size,String name,char type){ this.size=size; this.name=name; this.type=type; } public String toString(){ return "size"; } public static void main(String[] args) { // TODO Auto-generated method stub } }
and using the seralized object
package com.practice; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class ObjectIpOp { public void writefile(List<Animal> a) throws FileNotFoundException, IOException{ try(ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("E:\\AnimalData\\AnimalData.txt")))){ System.out.println("writting is in process"); for(Animal str : a) out.writeObject(str); System.out.println("writting is successful"); } } public void readfile(){ } public static void main(String[] args) throws FileNotFoundException, IOException { // TODO Auto-generated method stub Animal a = new Animal(12, "tom", 'a'); List<Animal> list = new ArrayList<Animal>(); list.add(new Animal(12, "tom", 'a')); ObjectIpOp op = new ObjectIpOp(); op.writefile(list); } }
in the E Directory the op is not displaying i am not un derstabding where i am wrong or i missed out the errors
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Serialization
Serialization
ObjectOutputStream ObjectInputStream
Query
Problem in Serialisation
More...