How to save data and load data from an arrayList ??

i got a run time problem .....when i try to save my data to a file and load a data from a file....i got some kind of error like that
Please enter your CD`s title : ivan
Please enter your CD`s Artist/GroupName : diw
Please enter your CD`s year of release : wid
InputMismatchException error occurred (the next token does not match the Integer regular expression, or is out of range) java.util.InputMismatchException
Invaild value....Please enter the value between 1000 & 9999
Please enter your CD`s MusicGenre(e.g.: Jazz, Blues, Funk, Classical, Rock, etc...) : w
Please enter your CD`s comment : w
Do you have another Cd ? (Y/N) : n
Saving to file
java.io.EOFException
     at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
     at java.io.ObjectInputStream.readObject0(Unknown Source)
     at java.io.ObjectInputStream.readObject(Unknown Source)
     at Demo.loadDate(Demo.java:49)
     at Demo.readDataFromConsole(Demo.java:103)
     at Demo.main(Demo.java:173)
Exit code: 0
import java.util.ArrayList;
import java.io.*;
public class Demo{
     readOperation theRo = new readOperation();
     errorCheckingOperation theEco = new errorCheckingOperation();
     ArrayList<MusicCd> MusicCdList;
     public Demo()
     private void heading()
          System.out.println("\tTesting read data from console, save to file, reopen that file\t");
     private void saveDate()
          MusicCdList = new ArrayList<MusicCd>( ); 
          try
               File f = new File("jessica.txt");
               FileOutputStream fos = new FileOutputStream(f);
               ObjectOutputStream oos = new ObjectOutputStream(fos);
               for( MusicCd s : MusicCdList)
               oos.writeObject(s);
               oos.close();
          catch (IOException ioe)
               ioe.printStackTrace();
     private void loadDate()
          MusicCdList = new ArrayList<MusicCd>( );  
          try
               File g = new File("jessica.txt");
               FileInputStream fis = new FileInputStream(g);
               ObjectInputStream ois = new ObjectInputStream(fis);
               ArrayList<String> stuff = (ArrayList<String>)ois.readObject();
               for( String s : stuff ) System.out.println(s);
               ois.close();
          } catch (Exception ioe)
               ioe.printStackTrace();
     private void readDataFromConsole()
     //private void insertCd()
       ArrayList<MusicCd> MusicCdList = new ArrayList<MusicCd>( ); 
        readOperation theRo = new readOperation();
        errorCheckingOperation theEco = new errorCheckingOperation();
        MusicCd theCd;
        String muiseCdsTitle;
        String muiseCdsArtistOrGroupName;
        int muiseCdsYearOfRelease;
        int validMuiseCdsYearOfRelease;
        String muiseCdsMusicGenre;
        String muiseCdsAComment;
          while(true)
                String continueInsertCd = "Y";
               do
                    muiseCdsTitle = theRo.readString("Please enter your CD`s title : ");
                    muiseCdsArtistOrGroupName = theRo.readString("Please enter your CD`s Artist/GroupName : ");
                    muiseCdsYearOfRelease = theRo.readInt("Please enter your CD`s year of release : ");
                    validMuiseCdsYearOfRelease = theEco.errorCheckingInteger(muiseCdsYearOfRelease, 1000, 9999);
                    muiseCdsMusicGenre = theRo.readString("Please enter your CD`s MusicGenre(e.g.: Jazz, Blues, Funk, Classical, Rock, etc...) : ");
                    muiseCdsAComment  = theRo.readString("Please enter your CD`s comment : ");
                    MusicCdList.add(new MusicCd(muiseCdsTitle, muiseCdsArtistOrGroupName, validMuiseCdsYearOfRelease ,
                    muiseCdsMusicGenre, muiseCdsAComment));
                    MusicCdList.trimToSize();
                    //saveToFile(MusicCdList);
                    continueInsertCd = theRo.readString("Do you have another Cd ? (Y/N) : ");
               }while(continueInsertCd.equals("Y") || continueInsertCd.equals("y") );
               if(continueInsertCd.equals("N") || continueInsertCd.equals("n"));
                                    System.out.println("Saving to file ");
                                                //MusicCdList.add(new MusicCd(muiseCdsTitle, muiseCdsYearOfRelease));     
                                                saveDate();
                                    loadDate();
                              break;
     public static void main(String[] args)
          Demo one = new Demo();
          one.readDataFromConsole();
          how should i fix it if i want to reach the save to a file and load from a file purpose??
thx all
for much more understand of this program
import java.io.Serializable;
public class MusicCd implements Serializable
     private String musicCdsTitle;
     private String artistOrGroupName;
        private int yearOfRelease;
     private String musicGenre;
     private String aComment;
     public MusicCd()
          musicCdsTitle = "";
          artistOrGroupName = "";
          yearOfRelease = 1000;
          musicGenre = "";
          aComment = "";
     public MusicCd(String newMusicCdsTitle, String newArtistOrGroupName, int newYearOfRelease,
     String newMusicGenre, String aNewComment)
          musicCdsTitle = newMusicCdsTitle;
          artistOrGroupName = newArtistOrGroupName;
          yearOfRelease = newYearOfRelease;
          musicGenre = newMusicGenre;
          aComment = aNewComment;
     public String getTitle()
          return musicCdsTitle;
     public String getArtistOrGroupName()
          return artistOrGroupName;
     public int getYearOfRelease()
          return yearOfRelease;
     public String getMusicGenre()
          return musicGenre;
     public String getAComment()
          return aComment;
     public void setTitle(String newMusicCdsTitle)
          musicCdsTitle = newMusicCdsTitle;
     public void setArtistOrGroupName(String newArtistOrGroupName)
          artistOrGroupName = newArtistOrGroupName;
     public void setYearOfRelease(int newYearOfRelease)
          yearOfRelease = newYearOfRelease;
     public void setMusicGenre(String newMusicGenre)
          musicGenre = newMusicGenre;
     public void setAComment(String aNewComment)
           aComment = aNewComment;
     public boolean equalsName(MusicCd otherCd)
          if(otherCd == null)
               return false;
          else
               return (musicCdsTitle.equals(otherCd.musicCdsTitle));
     public String toString()
          return("Title: " + musicCdsTitle + "\t"
          + "Artist/GroupName: " + artistOrGroupName + "\t"
          + "Year of release: " + yearOfRelease + "\t"
          + "Music Genre: " + musicGenre + "\t"
          + "Comment: " + aComment + "\t" );
}import java.util.*;
public class readOperation{
     public String readString(String userInstruction)
          String aString = null;
          try
     Scanner scan = new Scanner(System.in);
               System.out.print(userInstruction);
               aString = scan.nextLine();
          catch (NoSuchElementException e)
               //if no line was found
               System.out.println("\nNoSuchElementException error occurred (no line was found) " + e);
          catch (IllegalStateException e)
               // if this scanner is closed
               System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
          return aString;
     public char readTheFirstChar(String userInstruction)
          char aChar = ' ';
          String strSelection = null;
          try
               //char charSelection;
     Scanner scan = new Scanner(System.in);
               System.out.print(userInstruction);
               strSelection = scan.next();
               aChar = strSelection.charAt(0);
          catch (NoSuchElementException e)
               //if no line was found
               System.out.println("\nNoSuchElementException error occurred (no line was found) " + e);
          catch (IllegalStateException e)
               // if this scanner is closed
               System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
          return aChar;
     public int readInt(String userInstruction) {
          int aInt = 0;
          try {
               Scanner scan = new Scanner(System.in);
               System.out.print(userInstruction);
               aInt = scan.nextInt();
          } catch (InputMismatchException e) {
               System.out.println("\nInputMismatchException error occurred (the next token does not match the Integer regular expression, or is out of range) " + e);
          } catch (NoSuchElementException e) {
               System.out.println("\nNoSuchElementException error occurred (input is exhausted)" + e);
          } catch (IllegalStateException e) {
               System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
          return aInt;
import java.util.Scanner;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
public class errorCheckingOperation
     public int errorCheckingInteger(int checkThing, int lowerBound, int upperBound)
           int aInt = checkThing;
           try
                while((checkThing < lowerBound ) || (checkThing > upperBound) )
                     throw new Exception("Invaild value....Please enter the value between  " +  lowerBound + " & " +  upperBound );
           catch (Exception e)
             String message = e.getMessage();
             System.out.println(message);
           return aInt;
       public int errorCheckingSelectionValue(String userInstruction)
            int validSelectionValue = 0;
            try
                 int selectionValue;
                 Scanner scan = new Scanner(System.in);
                 System.out.print(userInstruction);
                 selectionValue = scan.nextInt();
                 validSelectionValue = errorCheckingInteger(selectionValue , 1, 5);
           catch (NoSuchElementException e)
               //if no line was found
               System.out.println("\nNoSuchElementException error occurred (no line was found) " + e);
          catch (IllegalStateException e)
               // if this scanner is closed
               System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
          return validSelectionValue;
}Message was edited by:
Ivan1238
Message was edited by:
Ivan1238

You should thoroughly check you code. It's full of problems.
For example in saveDate():
You create a new empty ArrayList and then want so save it's contents. I guess, the file size is always 0.
For example in loadDate():
Since you read from an empty file you get an EOFException. This is ok and you should catch and treat the exception properly.
You try to read the ArrayList instead of single MusicCd objects, although in saveDate you saved the single MusicCD objects. You can only read from the file what to saved in it before.
I suggest to write the size of the ArrayList as first object in the file. Then you know how much you can expect to read when loading from the file.
private void saveDate()
          try
               File f = new File("jessica.txt");
               FileOutputStream fos = new FileOutputStream(f);
               ObjectOutputStream oos = new ObjectOutputStream(fos);
                        oos.writeObject(new Integer(MusicCdList.size()));
               for( MusicCd s : MusicCdList)
               oos.writeObject(s);
               oos.close();
          catch (IOException ioe)
               ioe.printStackTrace();
     }

Similar Messages

  • How to save, update and retrieve data from two diffrent table

    Hi,
    I can save and retrieve data into an user defined SBO form from one database table only. How can I save retrieve and update records from two or more different tables in a single screen?
    Regards,
    Sudeshna.

    Sudeshna,
    Are these tables external to SAP Business One and do not have a Business Object?  If there is a Business Object available such as if you were to enter an order, that order would use the Documents object which abstracts you, the programmer, from the underlying tables that need to be updated.  If you are handling multiple business objects you would need to wrap the transaction with the StartTransaction - EndTransaction methods.  This information is detailed in the SAP Business One SDK Help Center that comes with the SDK.
    HTH,
    Eddy

  • How to save X and Y vaue from a Waveform Chart

    Hello Everyone!
    I'm implementing an adquisition systems that send data to a waveform Chart through VISA. All run properly, but I would like to save the data adquired to an excel file. I saw examples to how to save it, but only save the Y value.
    I would like getting the X and Y values in 2 columns different in the excel file.
    ¿Is it possible?
    ¿Can someone tell me how I can do it?
    Thanks for your feedbacks! 
    Solved!
    Go to Solution.

    I meant uploading the actual VI, not a picture of it. You need to fix your code.
    You should not be initializing the serial port in each iteration of the loop. Initialize outside, read in the loop, and close when the loop is done.
    Why do you have 2 VISA resource controls? Are you talking to 2 different devices?
    The event structure serves no purpose in your code. If you are trying to enable/disable the file writing, use a case structure that's controlled by a simple front panel switch.
    You should "remember" the path that the Write to Spreadsheet File uses. Otherwise you will be asked for the filename each and every time you try to save. You can do this using a simple Feedback Node:
    Since you are reading the value periodically, just use one of the Get Date/Time functions. You can use the Get Date/Time String to get a formatted string. Then you can format your value as a string, and build your array using those 2 values. Or, you can use the Get Date/Time in Seconds to get a numerical value. Be aware that LabVIEW's starting time is 12:00 a.m., Friday, January 1, 1904, Universal Time [01-01-1904 00:00:00], which is different from Excel. 
    Attachments:
    Example_VI_BD.png ‏1 KB

  • Delivery date and loading date is same

    Hello ,
    Issue decription:
    The system calculating delivery=loading date , though the route is maintained for 9 days trasit days.
    This problem is with only one routeA.
    When i have created SO for material M123 with route "B" shipping Point 0001, the system consider transit duration of the route.But when Sales order (SO )is placed for materail M123, shipping Point 0001, and route A, system is not considering the transit duration.
    Kindly let me know any config change is required with respect to route or forwarding agent.

    Hi,
    Check for the route A what's the transit duration time has maintained.The system uses the transit time from delivery scheduling as well as other time estimates (for example, the loading time) to determine the dates by which the goods must be available for picking, packing, and loading.Finally check the factory calendar if forwarding agent facory calendar has not maintaained it will consider the shipping point calendar.
    Regards,
    Hari Challa.

  • Planning Good Issue date and loading date

    Hi All,
    How I can get the planning Good issue date? I found that the loading date is the same as the planned Good issue date, what's the loading time?
    As what I understanding, loading date + loading time = Good issue date,  But I am not sure how to calculate the planned Good issue date.
    thanks,

    Hello Friend,
    It is determined in Shipping Point configuration.The path is as follows SPRO--> Enterprise Structure >Definition>Logistics Execution-->Define, copy, delete, check shipping point and go in detail the concerned shipping point.

  • How can I save my data and the date,the time into the same file when I run this VI at different times?

    I use a translation stage for the experiment.For each user in the lab the stage position (to start an experiment) is different.I defined one end of the stage as zero. I want to save the position , date and time of the stage with respect to zero.I want all these in one file, nd everytime I run it it should save to the same file, like this:
    2/12/03 16:04 13567
    2/13/03 10:15 35678
    So I will track the position from day to day.If naybody helps, I appreciate it.Thanks.

    evolution wrote in message news:<[email protected]>...
    > How can I save my data and the date,the time into the same file when
    > I run this VI at different times?
    >
    > I use a translation stage for the experiment.For each user in the lab
    > the stage position (to start an experiment) is different.I defined one
    > end of the stage as zero. I want to save the position , date and time
    > of the stage with respect to zero.I want all these in one file, nd
    > everytime I run it it should save to the same file, like this:
    > 2/12/03 16:04 13567
    > 2/13/03 10:15 35678
    >
    > So I will track the position from day to day.If naybody helps, I
    > appreciate it.Thanks.
    Hi,
    I know the function "write to spreadsheet file.vi"
    can append the data
    to file. You can use the "concatenate strings" to display the date,
    time as well as data... Hope this help.
    Regards,
    celery

  • How do you edit out the date and time stamp from a photo

    How do you edit out the date and time stamp from a photo

    You can blur it out with retouch
    The built-in "Retouch" brush in "Edit" mode should suffice, if the background is mostly uniform, and if you set the size of the brush to slightly wider than the bar width of the letters. For example, in this picture I removed the year from the date (in the lower right corner) by using the "retouch" brush and following the contours of the letters. (the screen shot is from iPhoto '11, but iPhoto 9 should give similar results).
    Regards
    Léonie

  • TS3276 Most attachments from a specific address (work) can not be opened, identified as winmail.data and no data available. Not sure if this is based on the e-mail coming from a windows based system, too old of a windows based system or simply how i have

    Most attachments from a specific address (work) can not be opened, identified as winmail.data and no data available. Not sure if this is based on the e-mail coming from a windows based system, too old of a windows based system or simply how i have it set on my Mac.

    Brightbleu wrote:
    Most attachments from a specific address (work) can not be opened, identified as winmail.data and no data available. Not sure if this is based on the e-mail coming from a windows based system, too old of a windows based system or simply how i have it set on my Mac.
    Winmail.data are not usable files. They just preserve RTF within the message.
    http://support.microsoft.com/kb/278061
    Cheers
    Pete

  • How to know date and time information from Trace File defaultTrace.X.trc?

    Hi, all.
      i'm using EP 6.0 SP9 patch 1.
      As you know, default trace is written in the <SID>\JC00\j2ee\cluster\server0\log\defaultTrace.X.trc.
      By using the default trace formatter, it shows like the following sample messages.
    #1.5#0011110E7B2000590000000100000A100003EC71562E6EBC#1104396451585#com.sap.jms.server.ServerClientAdapter##com.sap.jms.server.ServerClientAdapter#Guest#18####716257115a3f11d9b73b0011110e7b20#SAPEngine_Application_Thread[impl:3]_23##0#0#Error#1#/Applications/JMS#Plain###JMS internal error at ServerClientAdapter! JMS Service is not started!#
      My questions are
      1. how do we retrieve the date and time information from the above message? It seems that this message has date and time info because LogViewer shows the date and time based on the above message.
      2. how do we change the above date format to easier one
    like "YYYY:MM:DD:hh:mm:ss"? i know that it can be configured from the Visual Admin --> Services --> Log Configurator but i don't know the exact place for the trace file.
      Thanks.

    Hi Sejoon,
    I use the standalone Logviewer to read the log files. Works great.
    "If you have an SAP Web Application Server Java 6.20 or below you may also get a standalone_logviewer.zip file at the SAP Service Marketplace at service.sap.com/download &#8594; SAP NetWeaver &#8594; Release ‘04. In this case JDK version 1.3 or higher must be installed on the system. The java version must be same on the server and the client.
    In the SAP Web AS Java 6.30 installation a folder named logviewer_standalone can be found under: <path Of J2EE installation>/<SysID>/JC<nr>/j2ee/admin/logviewer_standalone. Verify that the batch file logviewer.bat is installed in the directory logviewer-standalone.
    (source -> http://help.sap.com/saphelp_nw04/helpdata/en/e4/540c404a435509e10000000a1550b0/frameset.htm)
    Best wishes,
    Noel

  • How to retrieve start and end date values from sharepoint 2013

    Hi,
    How to retrieve start and end date values from new event form of calendar in SharePoint foundation2013
    Thanks
    Gowri Balaguru

    Hi Srini
    Yes i need to have parallel flow for both and in the cube where my reporting will be on monthly basis i need to read these 2 master data and get the required attributes ( considering last/first day of that month as per the requirement).......but i am just wondering this is common scenario....while there are so many threads written for populating 0employee from 0person......don't they have such requirement.....
    Thanks
    Tripple k

  • How to find when and what date my iphone was first switched on from a retailer

    how to find when and what date my iphone was first switched on from a retailer

    Depending on the Code version you are running you can look for this output . It will show when a SFP was removed and inserted.
    module-2# show port-config internal all  (This command wil differ of earlier versions of SAN OS )
    Mar 20 08:53:45 2011  00449361  fc2/20         ---   DOWN   Xcvr inserted          
    Mar 20 08:53:32 2011  00829429  fc2/20         ---   DOWN   Disable                
    Mar 20 08:53:32 2011  00826403  fc2/20         ---   DOWN   Disable                
    Mar 20 08:53:32 2011  00818936  fc2/20         ---   DOWN   Xcvr removed  

  • How do I get date and time component from a DATE object?

    Hi All,
    I need to get date and time separately from a DATE object, does
    anyone know what function I should call? GetDate()? GetTime()?
    I need this in a SELECT statement.
    Thanks in advance and looking forward to your early reply.
    Regards.
    Gladywin
    30/11/2001

    Hello,
    See following SQL.
    select to_char(sysdate,'dd/mm/rrrr') today_date,
    to_char(sysdate,'hh24:mi') now_time
    from dual
    Adi

  • How can I instantiate and load a new CachedRowSet object from a non-JDBC so

    How can I instantiate and load a new CachedRowSet object from a non-JDBC source?
    cheers

    webrowset reads whole data;
    I would rather need to get data line by line

  • How to Save Multiple Records In Data Block

    Hi All,
    I Have Two Blocks --> Control Block,Database Block
    Please Any Idea How to Save Multiple Records In Data Block when User changed Data in Control Block.
    Thanks For Your Help
    Sa

    Now i have to use each record of control block(ctl_blk) as where condition in data base block(dat_blk)and display 10 records from database table.>
    Do you want this coordination to be automatic/synchronized or only when the user clicks a button or something else to signal the coordination? Your answer here will dicate which trigger to put your code in.
    As to the coordination part, as the user selects a record in the Control Block (CB), you will need to take the Key information and modify the Data Block's (DB) "DEFAULT_WHER E" block property. The logical place to put this code is the CB When-New-Record-Instance (WNRI) trigger. You code will look something like the following:
    /* Sample WNRI trigger */
    /* This sample assumes you do not have a default value in the BLOCK WHER E property */
    DECLARE
       v_tmp_dw    VARCHAR2(250);
    BEGIN
       v_tmp_dw := ' DB_Key_Column1 = '||:CONTROL.Key_Column1||' AND DB_Key_Column2 = '||:CONTROL.Key_Column_2;
       Set_Block_Property('DATA_BLOCK', DEFAULT_WHER E, v_tmp_df);
       /* If you want auto coordination to occur, do the following */
       Go_Block('DATA_BLOCK');
       Execute_Query;
       /* Now, return to the Control Block */
       Go_Block('CONTROL_BLOCK');
    END;
    The Control block items are assigned with values in Form level (Key_exeqry).If your CD is populated from a single table, it would be better to create a Master - Detail relationship (as Abdetu) describes.
    Hope this helps,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • How to update link and import data of relocated incx file into inca file?

    Subject : <br />how to update link and import data of relocated incx file into inca file.?<br />The incx file was originally part of the inca file and it has been relocated.<br />-------------------<br /><br />Hello All,<br /><br />I am working on InDesignCS2 and InCopyCS2.<br />From indesign I am creating an assignment file as well as incopy files.(.inca and .incx file created through exporing).<br />Now indesign hardcodes the path of the incx files in inca file.So if I put the incx files in different folder then after opening the inca file in InCopy , I am getting the alert stating that " The document doesn't consists of any incopy story" and all the linked story will flag a red question mark icon.<br />So I tried to recreate and update the links.<br />Below is my code for that<br /><br />//code start*****************************<br />//creating kDataLinkHelperBoss<br />InterfacePtr<IDataLinkHelper> dataLinkHelper(static_cast<IDataLinkHelper*><br />(CreateObject2<IDataLinkHelper>(kDataLinkHelperBoss)));<br /><br />/**<br />The newFileToBeLinkedPath is the path of the incx file which is relocated.<br />And it was previously part of the inca file.<br />eg. earlier it was c:\\test.incx now it is d:\\test.incx<br />*/<br />IDFile newIDFileToBeLinked(newFileToBeLinkedPath);<br /><br />//create the datelink<br />IDataLink * dlk = dataLinkHelper->CreateDataLink(newIDFileToBeLinked);<br /><br />NameInfo name;<br />PMString type;<br />uint32 fileType;<br /><br />dlk->GetNameInfo(&name,&type,&fileType);<br /><br />//relink the story     <br />InterfacePtr<ICommand> relinkCmd(CmdUtils::CreateCommand(kRestoreLinkCmdBoss)); <br /><br />InterfacePtr<IRestoreLinkCmdData> relinkCmdData(relinkCmd, IID_IRESTORELINKCMDDATA);<br /><br />relinkCmdData->Set(database, dataLinkUID, &name, &type, fileType, IDataLink::kLinkNormal); <br /><br />ErrorCode err = CmdUtils::ProcessCommand(relinkCmd); <br /><br />//Update the link now                         <br />InterfacePtr<IUpdateLink> updateLink(dataLinkHelper, UseDefaultIID()); <br />UID newLinkUID; <br />err = updateLink->DoUpdateLink(dl, &newLinkUID, kFullUI); <br />//code end*********************<br /><br />I am able to create the proper link.But the data which is there in the incx file is not getting imported in the linked story.But if I modify the newlinked story from the inca file,the incx file will be getting update.(all its previous content will be deleted.)<br />I tried using <br />Utils<IInCopyWorkflow>()->ImportStory()<br /> ,But its import the incx file in xml format.<br /><br />What is the solution of this then?<br />Kindly help me as I am terribly stuck since last few days.<br /><br />Thanks and Regards,<br />Yopangjo

    >
    I can say that anybody with
    no experience could easily do an export/import in
    MSSQLServer 2000.
    Anybody with no experience should not mess up my Oracle Databases !

Maybe you are looking for