• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to pass Vector's object thru a stream

 
karthik ts
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
I have no idea about passing Vector's object thru the proper stream.
I have stored some values in the Vector which would get erased during the mouseRelease Event. Never bother about it!
But tell me how to transfer the object of the vector inside
Thanx
___karthik
 
Sandeep Jain
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
what u can do is make use of objectInputStream and ObjectOutputStreams in ur program . I have written two small programs just check it out i it helps u or not .
//writeVector.java
import java.io.*;
import java.util.Vector;
class writeVector implements Serializable
{
Vector v;
public static void main(String[] args)
{
new writeVector();
}
public writeVector()
{
try
{
v=new Vector();
v.add("one");
v.add("two");
v.add("Three");
ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("trial.txt"));
out.writeObject(v);
out.close();
}
catch(Exception e)
{
System.out.println("Exception "+e);
}
}
}
//ReadVector.java
import java.io.*;
import java.util.Vector;
class readVector implements Serializable
{
Vector v;
public static void main(String[] args)
{
new readVector();
}
public readVector()
{
try
{
ObjectInputStream out=new ObjectInputStream(new FileInputStream("trial.txt"));
v=(Vector)out.readObject();
for(int i=0;i<v.size();i++)>
{
System.out.println(v.get(i));
}
out.close();
}
catch(Exception e)
{
System.out.println("Exception "+e);
}
}
}

------------------
Sandeep Jain
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!