Retreiving more than one object from an object stream using serialization.

I have written a number of object into a file using the object Output stream. Each object was added separately with a button event. Now when I retrieve it only one object is being displayed. the others are not displayed The code for retrieval and inserting is given below. Please do help me.
code for inserting is as follows
Vehicle veh1 and vehicle class implements serializable
veh1.vehNum=tf1.getText();
          veh1.vehMake=tf2.getText();
          veh1.vehModel=tf3.getText();
          veh1.driveClass=tf4.getText();
          veh1.vehCapacity=tf5.getText();          
          FileOutputStream out = new FileOutputStream("vehicle.txt",true);
          ObjectOutputStream s = new ObjectOutputStream(out);
          s.writeObject(veh1);
retrieval
FileInputStream out = new FileInputStream("vehicle.txt");
          String str1,str2;
          str1=str2=" ";
          Vehicle veh=new Vehicle();
          ObjectInputStream s = new ObjectInputStream(out);
          try
          Vehicle veh1=(Vehicle)s.readObject();
          s.close();
          int i=0;
          str1=veh1.vehNum;
          str2+=str1+"\t";
          str1=veh1.vehMake;
          str2+=str1+"\t";
          str1=veh1.vehModel;
          str2+=str1+"\t";
          str1=veh1.driveClass;
          str2+=str1+"\t";
          str1=veh1.vehCapacity;
          str2+=str1+"\t\n";
          ta1.append(str2);
          catch(Exception e)
          e.printStackTrace();
Pleas give me the code for moving through the object until it reaches the end of file

You can read objects from the stream one by one. So, what you need is an endless loop like this:
// Suppose you have an ObjectInputStream called objIn
// So here is the loop which reads objects from the stream:
Object inObj;
while (1) {
    try {
        inObj=objIn.readObject();
        // Do something with the object we got
        parse_the_object(inObj);
    } catch (EOFException ex) {
        // The EOFException will be thrown when
        // we reached the end of the file, so here we break out
        // of our lovely infinite cycle
        break;
    } catch (Exception ex) {
        ex.printStackTrace();
        // Here you may decide what to do...
        // Probably the processing will end here, too. For now,
        // we moving on, hoping there is still something to read
objIn.close();
// ...

Similar Messages

  • Transferring photos in more than one folder from PC to iPad using iTunes

    In iTunes, if I sync photos in folder "A" on my PC with iPad and at a later time sync with folder "B" on the PC, will the photos that were originally synced with folder "A" be erased from the iPad?

    Anyhting you have selected will be on the ipad.
    If you deselect it, or it is not on your computer, then it will not be on the ipad.
    Ipad simply mirrors the selected content of your computer

  • How can i transfer more than one file from server to client

    Hi,
    our requirement is transfer more than one files from server to client using the
    webutil_file_transfer.as_to_client_with_progress.One file transfer is already working in our system.If anybody know the solution please inform
    regards
    mat

    just an idea ...
    for this purpose let us put aside security concerns and other potential problems....
    -- Get the content of a server directory with Filter and create zip file
    1) create a class that implements java.io.FilenameFilter ...
    2) define accept() method ...
    3) call File.list() with the filter as a parameter. The returned array of strings will have all the names that passed through the accept() filter
    4) use java.util.Zip to create ZIP file on the server side
    -- I think it is better to create this functionality as a separate Java class, put it in required folder and after it
    -- use Forms->Program->"Import Java class" to create pl/sql wrappers, than to create wrappers for all classes and code in pl/sql
    5) use webutil to transfer file on the client
    6) use Java on client side to unzip transferred file
    if you think this is not too complicated, you should try ...
    Regards,
    Vladimir

  • Methods that return more than one object.

    Hello everyone,
    I don't know if this has ever been proposed or if there's an actual solution to this in any programming language. I just think it would be very interesting and would like to see it someday.
    This is the thing: why isn't it possible for a method to return more than one object. They can receive as many parameters as wanted (I don't know if there's a limit), but they can return only 1 object. So, if you need to return more than one, you have to use an auxiliary class...
    public class Person {
       private String name;
       private String lastName;
       public Person(String name, String lastName) {
          this.name = name;
          this.lastName= lastName;
       public String getName() {
           return name;
       public String getLastName() {
           return lastName;
    }So if you want to get the name of somebody you have to do this, assuming "person" is an instance of the object Person:
    String name = person.getName();And you need a whole new method (getLastName) for getting the person's last name:
    String lastName = person.getLastName();Anyway, what if we were able to have just one method that would return both. My idea is as follows:
    public class Person {
       private String name;
       private String lastName;
       public Person(String name, String lastName) {
          this.name = name;
          this.lastName= lastName;
       public String name, String lastName getName() {
           return this.name as name;
           return this.lastName as lastName;
    }And you would be able to do something like:
    String name = person.getName().name;and for the last name you would use the same method:
    String lastName = person.getName().lastName;It may not seem like a big deal in this example, but as things get more complicated simplicity becomes very useful.
    Imagine for example that you were trying to get information from a database with a very complex query. If you only need to return 1 column you have no problem, since your object can be an array of Strings (or whatever type is necessary). But if you need to retrieve all columns, you have three options:
    - Create 1 method per column --> Not so good idea since you're duplicating code (the query).
    - Create and auxiliary object to store the information --> Maybe you won't ever use that class again. So, too much code.
    - Concatenate the results and then parse them where you get them. --> Too much work.
    What do you think of my idea? Very simple, very straight-forward.
    I think it should be native to the language and Java seems like a great option to implement it in the future.
    Please leave your comments.
    Juan Carlos García Naranjo

    It's pretty simple. In OO, a method should do one thing. If that thing is to produce an object that contains multiple values as part of its state, and that object makes sense as an entity in its own right in the problem domain--as opposed to just being a way to wrap up multiple values that the programmer finds it convenient to return together--then great, define the class as such and return an instance. But if you're returning multiple values that have nothing to do with each other outside of the fact that it's convenient to return them together, then your method is probably doing too much and should be refactored.
    As for the "if it increases productivity, why not add it?" argument, there are lots of things that would "increase productivity" or have some benefit or other, but it's not worth having them in the language because the value they add is so small as to no be worth the increase in complexity, risk, etc. MI of implementation is one great example of something that a lot of people want because it's convenient, but that has real, valid utility only in very rare cases. This feature is another one--at least in the domain that Java is targetting, AFAICT.

  • If possible, one SoftReference refer to more than one object?

    Hello,
    I want design a cache to keep huge number objects.
    If create a new SoftReference intance for each object,
    will take a lot of space and time.
    So, one SoftReference refer to more than one object, if possible?

    or arrange your objects into buckets somehow and have
    soft references to the bucketsEn, It's a good idea. but I think it doesn't work.
    My problem is:
    There are many caches(cache1, cache2.......), they may cache a lot of same object instance.
    then, I want to keep a object pool, and try to get the equal object from pool before put a object into a cache, if there is an equal object, put the equal object into cache, if there is no equal object, put the target object into pool and cache. the object pool may very huge because there is lot of objects. So it's necessary to release the object in the pool if no cache referes to the object(the caches contain the object may removed). Then SoftReference come into my mind. I try to create a SoftReference for each object in the pool, but soonly, I find there are two problems:
    1, A lot SoftReference instances take much memory.
    2, Need some time to new and reclaim the SoftReference intances.
    I think SoftReference may work fine to cache the object frequently used,
    but the object number can't be too large.
    Now, I don't use object pool. replace starting a thread to scan those cache s and combine the same objects intervally. It can scan about 2000,000 objects one second in my pc. It's ok for my project. But I am looking for some better way still.

  • [Q] Can Vision track more than one object in a same area - objects that might cross?

    Hi,
    Sorry for that long title, but that's my question.
    Can Vision track more than one object in a same area - objects that might cross?
    Because I'm able to do it, extracting XY, but it looks like "IMAQ Count Objects" doesn't track object frame after but frame, but extract the XY coordinates always in the same way, like example starting from top and everytime he sees an object, he extracts the XY, but if the objects cross (then he will extract XY without caring which objects was the previous one but just based on "scan from top to bottom").
    This is why I opened this topic in the non Vision forum part : http://forums.ni.com/t5/LabVIEW/Sort-XY-by-closest/td-p/2440428
    Thank you,
    Sébastien
    Solved!
    Go to Solution.

    Hi,
    In fact, IMAQ count object order the object regarding their top most and left most pixel, but not regarding their gravity center point.
    Axis origin of an image is situated on the left top corner.
    You need to refer to other caracteristics such as shape or color to identify your objects.
    Regards

  • Selecting more than one object at a time

    Hi guys and girls
    I am trying to select more than one object on my artboard and Shift+clicking on the next one isn't working...
    I am creating an interactive form in Indesign and realised that I have everything on one layer... I have radio buttons for yes/no questions and I wanted to move them to a new layer for ease of selection and editing...
    I have tried selecting one and then Shift+Click on the next but it just moves which one is selected...?
    I even tried creating a new layer and dragging them up to the new layer...no Dice?
    Has anyone any ideas....Please!
    bookie56
    P.S. Just realised that the radio buttons are part of the text? Could this be the reason why I can't move them. Doesn't solve the question about selection though

    Hi AnshulJain19
    OK! sort of guessed that....thanks for coming by.
    I am still on this form and have created multiline text boxes for two of my text boxes.... have checked the positioning of the boxes - but when I write in the box in Adobe Acrobat the text is quite a long way above the line...this is only happening with the multiline boxes.
    Is there a way to export a font colour for the boxes or does this need to be done in Acrobat Reader...?
    I have a standard dark background for my page and that needs a White font...when I fill the form in it is black...
    bookie56

  • Crystal Report - More than one table from MySql

    Hello, I am in need of help big time.
    I have am using Visual Studio 2010 and Crystal Report 10.
    The problem that I am incounting is that I am unable to retreive data from more than one table from a MySql database. I have been stuck on this for too long and need to hjump the hurdle.
    I am using a MySql connection string, a dataset and a crystal report which is based on the dataset.
    The main error that I am having is, the browser opens and a form appears saying "The report you requetsed requires further information" With the Server name: DataSetPropertiesDetials, while the User name and Password fields are then enabled.
    I am guessing I am missing something in my code.
    When I retreive data from one table the report is fine, but when I try to use more than one table it throws the error.
    My Code is below and also attached:
    Imports System.Data.SqlClient
    Imports System.Configuration
    Imports MySql.Data.MySqlClient
    Imports CrystalDecisions.ReportSource
    Imports CrystalDecisions.Web
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Shared
    Public Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim con As MySqlConnection
    Dim rpt As New CrystalReport3()
    Dim myReport As New ReportDocument
    Dim myData As New DataSet
    Dim cmd As New MySqlCommand
    Dim cmdUser, cmdProperty, cmdBranch As New MySqlCommand
    Dim daBranch, daProperty, daUser As New MySqlDataAdapter
    con = New MySqlConnection()
    'Connection String
    con.ConnectionString = "Server=****;Database=***;UID=***;Password=****"
    Try
    con.Open()
    cmdBranch.CommandText = "SELECT branch FROM tblbranch"
    cmdBranch.Connection = con
    daBranch.SelectCommand = cmdBranch
    daBranch.Fill(myData)
    cmdProperty.CommandText = "SELECT ref, keys_held, key_no, keys_out, no_name, address_line1, address_line2,key_label FROM tblproperty"
    cmdProperty.Connection = con
    daProperty.SelectCommand = cmdProperty
    daProperty.Fill(myData)
    cmdUser.CommandText = "SELECT known_name FROM tbluser"
    cmdUser.Connection = con
    daUser.SelectCommand = cmdUser
    daUser.Fill(myData)
    myReport.Load("REPORT LOCATION")
    myReport.SetDataSource(myData)
    myReport.Database.Tables(0).SetDataSource(myData.Tables(0))
    CrystalReportViewer1.ReportSource = myReport '
    Catch myerror As MySqlException
    MsgBox(myerror.Message)
    End Try
    End Sub
    End Class

    Hi, 
    You have 3 SQL commands but you are calling SetDataSource only once.  You need to look through for each of the SQL Commands. 
    Good luck,
    Brian

  • Connect to more than one Database from portal

    I need to reach more than one database from my portal. How is this done?

    You have several options depending on what you want to do with the data.
    1) Omniportlet: you can specify on a per portlet instance basis to what DB you want to connect (JDBC).
    2) Programmatic Java portlet: you can create as many JDBC connections as you like.
    3) DB links: you can build data-driven portlets on database objects, accessed via DB links.
    4) Programmatic PL/SQL portlet: you can build programmatic PL/SQL portlets on database objects, accessed via DB links.
    Peter

  • How to restrict more than one delivery from one sales order.

    Hi Guys,
    We have a requirement that is, system should not allow more than one delivery from one sales order no even if when there is some line item still to be delivered.
    We want only one delivery for one sales order and rest of line items should be treated as rejected.
    Kindly help
    Thanks in advance,
    Balu

    Hi MP,
    Its also not working as we have the requirement is that once sales order is saved and one delivery is created then again if we are adding some more item inthe same sales order then system should not allow to create delivery document as one delivery already created.
    Thanks,
    Balu.
    Edited by: Balu Sajja on Aug 30, 2010 1:29 PM

  • How can I select more than one song from the search results?

    I want to create playlists based on certain words in the song title. For example, I may want to create a playlist of all my songs with LOVE in the title.
    Doing the search is easy, but I can't select more than one song at a time. Is there any way in iTunes 12 for Windows to do this? I found an answer in iTunes for Mac, and it basically says to "un-check "Search Entire Library." " but I don't see that option in iTunes for Windows.
    Here is the link to that question: how can i select more than one song from drop down search bar
    I hope some Windows user can help me out.

    Found the "Search Entire Library" option - click on the small (VERY small for my eyesight) down arrow next to the magnifying glass. Also need to select "Filter by: Songs", and then the songs in the main window show the results.
    I'm going to leave this up on the board because 1) in case someone else has this question, and 2) I don't know how to delete it anyway.

  • Since downloading the iOS on my iPad, I cannot download more than one pdf from mail to iBooks.  I have to shut down y iPad and start again.  Any suggestions?

    Since downloading iOS on my new iPad, I cannot downlaod more than one pdf from mail into iBooks.  I have to shut down my iPad and restart it to save a second pdf. Wasn't a problem with the old operating system.  Any suggestions?

    It seems that I have solved my issue by performing a full factory reset (erasing all content, something which I had hoped to avoid) restoring from an iCloud backup did not alleviate the issue, I had to set up as a new iPad.
    Hopefully anyone else else who has this issue in the future will be able to find this.

  • How to email more than one photo from camera roll

    How do e-mail more than one photo from the camera roll at a time?

    Go to the camera roll, open the thumbnails, click on the arrow in the top right, select up to 5 photos, click on share in the top left and select email.

  • Can I change more than one photo from color to black and white at one time?

    can I change more than one photo from color to black and white at one time?

    Check out iPhoto Batch Enhancer
    http://www.feroxsoft.com/ibe/index.php.en
    Regards
    TD

  • Can I manage more than one iTouch from one PC?

    A family member has an iTouch managed with iTunes on PC. Another family member would like an iTouch but does not have a computer.
    Can one manage more than one iTouch from one PC? How? Does one install separate instances of iTunes somehow on the PC for each device?
    There is also the desire to have separate Apple Store accounts for each device. We don't what synced devices.

    *How to use multiple iPods with one computer*
    The Apple support document How to use multiple iPods with one computer suggests a number of ways. I use method two (Sync with selected playlists) with a slight twist. Rather than regular playlists I set the grouping field to indicate which users should receive which tracks and create smart playlists based on the content of this field.
    e.g.
    "Alice's Tracks" is "Grouping contains Alice" + "Kind contains audio"
    "Bob's Videos" is "Grouping contains Bob" + "Kind does not contain audio"
    Tracks that both Alice & Bob want on their iPods have the grouping set to "Alice/Bob"
    etc.
    I currently manage our family's five iPods using this system, each getting a different selection to suit their tastes and the capacity of their iPod. An advantage of using the grouping field is that it is stored in file tags (for non-wav audio files anyway) so that it is relatively easy to recreate the playlists should the iTunes library get trashed. Also useful if you move files about manually as playlist membership is preserved when you delete & re-import the tracks.
    tt2

Maybe you are looking for