How to write an object to a file.

I have a LinkedList called my data. Is there a way to write this object to a file instead of having to convert the data to delimited string values and storing it in a sequential file?

this is how i write and read objects to a file:
     public void write() {
          try {
               oos = new ObjectOutputStream(new FileOutputStream(fileName));
               oos.writeObject(data);
               oos.flush();
               oos.close();
          } catch (Exception e) {
               System.out.println(e.toString());
     public void read() {
          try {
               ois = new ObjectInputStream(new FileInputStream(fileName));
               data = (LinkedList)ois.readObject();
               ois.close();
          } catch (FileNotFoundException fnf) {
               System.out.println("noFileFound");
          } catch (Exception e) {
               System.out.println(e.toString());

Similar Messages

  • How to write data to an XML file present under application server

    frnds: can ne one tell me, how to write data in to a file, which is present under a application server
    Ex: i want to write a string data in to a file test.txt which is present under "http://localhost:8080/<some_webapp>/test.txt"
    Note:i have deploted a service<some_webapp> under Tomcat/webapps dir

    Very simple. A servlet can writes to that file if it has the good rights.
    In the servlet get (or post) method, use a code like this:
    import java.io.*;
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    try {
    String filePath = this.getServletContext().getRealPath("/text.txt");//See http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/ServletContext.html#getRealPath(java.lang.String)
             PrintWriter writer = new PrintWriter (filePath);
            //or BufferedWriter out = new BufferedWriter(new FileWriter(filePath));
            writer .println("aString");
           writer.flush();
            writer .close();
        } catch (Exception e) {
           e.printStackTrace();
    }Hope That Helps

  • How to write new line to a File?

    How to write new line to a file?
    I have a string to be written to a file. the string contains "\n" in it. But why it is not showing the new line in the file.
    I have tryed FileWriter class and FileOutputStream class, but none of them works?
    any suggestion please...

    Probably using PrintStream::println() is a portable way.
    import java.io.FileOutputStream;
    import java.io.PrintStream;
    public class NewLine {
        public static void main(String[] args) {
         try {
             PrintStream ps = new PrintStream(new FileOutputStream("foo.txt"));
             ps.write("string".getBytes());
             ps.println();
             ps.close();
         } catch (java.io.IOException e) {
             e.printStackTrace();
    }Regards,

  • How to write multiple inputs into 1 file + how to use PWM

    hi,
    I wanna take analog inputs from 2 channels, then write them into a single file, have them the data plotted on 1 graph.  how can I do that?
    also, I wanna output 2 PWM signal lines after some calculations with the data of those 2 channels.  how can I do it?
    another thing:
    can I use Labview to make a state-obersver program?
    the board I am using has part number:  183554C-01.  it is a DAQ Signal Acessory.

    hope this helps:
    Harold Timmis
    [email protected]
    Orlando,Fl
    *Kudos always welcome
    Attachments:
    senddatatoonefile.vi ‏15 KB

  • How to write sql command in batch file

    hi,
    i m using oracle 9i on windows. i want to know how can i write sql command on batch file. i want to use a batch file to use sql command like shutdowm & startup command and any select command too.
    so plz tell how can i do it ?
    thxs

    superdba wrote:
    thxs u all , i got it at i wanted to do.
    thaks u all for yr precious time.
    thxsYou've 67 questions with 63 UNanswered. Please mark this question as "answered" and give points to the users whose answer you accept as "helpful" or "correct"
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com
    [Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/]

  • How to write/insert lines in a file from top

    I am opening a writing to a file as follows:
    (part of the code which does so)
    FileOutputStream file; // declare a file output object
    PrintStream r;
    file = new FileOutputStream("filename") + ".properties",true);
    r = new PrintStream( raj);
    r.println ( value + "=" + data.getString(value) );
    r.close();
    This prints in file line after line like
    A
    B
    C
    How can I make it to print/insert new line right at the top ?
    That is if I print A, then B, then C, how can I make it to get
    C
    B
    A
    in the file ?
    Help is much appriciated.

    Use a RandomAccessFile then you can position the
    cursor anywhere in the file.Yes, but that still doesn't allow data to be inserted unless all following data is shifted to make room for the insertion. (If you don't shift, the inserted data will overwrite following data already there.)

  • How to write empty line in text file

    hey
    i want to insert one empty line in text file.
    how to write this.
    i declared
    data: emptyrec(240) type c value space,
    and used
    TRANSFER emptyrec to e_file.
    but its not inserting empty line in the record.
    is there any special way have to do.
    ambichan.

    hai anand,
    I am posting the code snippet.
    i have commented that transfer line in '----
    ' like this
    pls refer below.
    ambichan
    DATA: PAGENO(4) TYPE N VALUE 1,
          DATAKBN(2) TYPE N VALUE 1,
          SUBNO(3) TYPE N VALUE 1,
          VPAGENO(4) TYPE C,
          VDATAKBN(2) TYPE C,
          VSUBNO(3) TYPE C,
          VREC(255) TYPE C,
          VRECORD(255) TYPE C,
          EMPTYREC(255) TYPE C VALUE SPACE,
          VCODE(10) TYPE C,
          VNAME2(35) TYPE C,
          VPAYDAT(10) TYPE C,
          VSGTXT(60) TYPE C VALUE SPACE,
          VSGTXT1(10) TYPE C,
          VKINGAKU(15) TYPE C VALUE SPACE,
          VBIKKO(30) TYPE C VALUE SPACE,
          VBELNR(10) TYPE C VALUE SPACE,
          VDMBTR(15) TYPE C,
          VGLT0-KSLVT(15) TYPE C,
          VGLT0-TSL01(15) TYPE C,
          VGLT0-TSL02(15) TYPE C,
          VGLT0-TSL03(15) TYPE C,
          VGLT0-TSL04(15) TYPE C,
          VGLT0-TSL05(15) TYPE C,
          VKIN(15) TYPE C,
          VTEGA(15) TYPE C.
    FORM FRM_OUTPUT_DATA.
      SORT ITAB_OUTPUT_SUMMARY BY LIFNR DTYPE.
      SORT ITAB_OUTPUT_ITEMS   BY LIFNR DTYPE BELNR.
    IF P_DISP = 'X'."check&#12508;&#12463;&#12473;&#12434;&#36984;&#12406;&#22580;&#21512;&#12289;&#12501;&#12449;&#12452;&#12523;&#20316;&#25104;&#20966;&#29702;&#12408;&#34892;&#12367;
    OPEN DATASET E_FILE FOR OUTPUT IN TEXT MODE.
      IF SY-SUBRC <> 0.
      WRITE: 'error',SY-SUBRC.
      EXIT.
      ENDIF.
    LOOP AT ITAB_LIFNR.
      PERFORM LISTDATA.
      PAGENO = PAGENO + 1.
      SUBNO = 1.
    ENDLOOP.
    CLOSE DATASET E_FILE."&#12501;&#12449;&#12452;&#12523;&#12463;&#12525;&#12540;&#12474;
    ENDFORM.                               " End of frm_output_data
    FORM LISTDATA.
      DATA:
        WK_PAY_AMOUNT  LIKE  BSEG-DMBTR,   " &#32020;&#25903;&#25173;&#38989;&#31639;&#20986;&#29992;
        VWK_PAY_AMOUNT(15) TYPE C,
        GLT0-TSL05_VAL LIKE GLT0-TSL05.
      READ TABLE ITAB_OUTPUT_SUMMARY
             WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 1.
    BSIK-DMBTR  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
      GLT0-TSL01  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
      READ TABLE ITAB_OUTPUT_SUMMARY
             WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 2. " &#21306;&#20998;&#65306;2
      GLT0-TSL02  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
      READ TABLE ITAB_OUTPUT_SUMMARY
             WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 3. " &#21306;&#20998;&#65306;3
      GLT0-TSL03  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
      READ TABLE ITAB_OUTPUT_SUMMARY
             WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 4. " &#21306;&#20998;&#65306;4
      GLT0-TSL04  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
      READ TABLE ITAB_OUTPUT_SUMMARY
             WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 5. " &#21306;&#20998;&#65306;5
      GLT0-TSL05  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
    glt0-tsl05  =  glt0-tsl05  +  glt0-tsl04.
      WK_PAY_AMOUNT  =  GLT0-TSL05  +  GLT0-TSL04.
    CHECK WK_SUBRC = 0.                
      BSEG-KOART = ' '.                    &#24773;&#22577;&#19981;&#35201;
      CLEAR: BSEG-SGTXT, BSEG-DMBTR, TGSBT-GTEXT, BKPF-BELNR.
      BSEG-KOART = 'Y'.                    " &#12501;&#12521;&#12464;&#65306;&#12504;&#12483;&#12480;&#12395;&#30456;&#27578;&#38989;&#12434;&#20986;&#21147;
    CLEAR: BSAK-DMBTR.
      READ TABLE ITAB_OUTPUT_SUMMARY
           WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 6.  " &#21306;&#20998;&#65306;6
      BSAK-DMBTR  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
      WK_PAY_AMOUNT  =  WK_PAY_AMOUNT  -  BSAK-DMBTR.
      WRITE : / PAGENO,
               SUBNO,
               DATAKBN,
               ITAB_LIFNR-LIFNR,
               ITAB_LIFNR-NAME2(25),
               P_PAY_T,
               GLT0-TSL01,
               GLT0-TSL02,
               GLT0-TSL03,
               GLT0-TSL04,
               GLT0-TSL05.
    VPAGENO = PAGENO.
    VSUBNO = SUBNO.
    DATAKBN = 1.
    VDATAKBN = DATAKBN.
    VCODE = ITAB_LIFNR-LIFNR.
    VNAME2 = ITAB_LIFNR-NAME2.
    VPAYDAT = P_PAY_T.
    VGLT0-TSL01 = GLT0-TSL01.
    VGLT0-TSL02 = GLT0-TSL02.
    VGLT0-TSL03 = GLT0-TSL03.
    VGLT0-TSL04 = GLT0-TSL04.
    VGLT0-TSL05 = GLT0-TSL05.
    CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT VKINGAKU
    VBIKKO VBELNR VGLT0-TSL01 VGLT0-TSL02 VGLT0-TSL03
    VGLT0-TSL04 VGLT0-TSL05 INTO VREC SEPARATED BY ','.
    CLEAR: BSAK-DMBTR, BSID-DMBTR, BSAD-DMBTR, BSEG-DMBTR, BSIK-DMBTR,
             WK_10 , WK_11 , GLT0-TSL05.
      READ TABLE ITAB_OUTPUT_SUMMARY
           WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 7.  " &#21306;&#20998;&#65306;7
      BSID-DMBTR  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
      WK_PAY_AMOUNT  =  WK_PAY_AMOUNT  -  BSID-DMBTR.
    &#37109;&#36865;&#26009;&#12398;&#20986;&#21147;&#20966;&#29702;
      READ TABLE ITAB_OUTPUT_SUMMARY
           WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 8.  " &#21306;&#20998;&#65306;8
      BSAD-DMBTR  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
      WK_PAY_AMOUNT  =  WK_PAY_AMOUNT  -  BSAD-DMBTR.
      READ TABLE ITAB_OUTPUT_SUMMARY
           WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 9.  " &#21306;&#20998;&#65306;9
      BSEG-DMBTR  =  ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
      WK_PAY_AMOUNT  =  WK_PAY_AMOUNT  -  BSEG-DMBTR.
      READ TABLE ITAB_OUTPUT_SUMMARY
             WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 10.
      WK_10 =     ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
      READ TABLE ITAB_OUTPUT_SUMMARY
             WITH KEY   LIFNR  =  ITAB_LIFNR-LIFNR  DTYPE = 11.
      WK_11 =     ITAB_OUTPUT_SUMMARY-DMBTR * WK_RATIO.
      GLT0-TSL05  =   WK_PAY_AMOUNT - WK_10 - WK_11.
      WK_PAY_AMOUNT  =  WK_PAY_AMOUNT  -  GLT0-TSL05.
       VWK_PAY_AMOUNT = WK_PAY_AMOUNT.
       VKIN = WK_10.
       VTEGA = WK_11.
       CONCATENATE VREC VWK_PAY_AMOUNT VKIN VTEGA INTO
             VRECORD SEPARATED BY ','.
       TRANSFER VRECORD TO E_FILE.
        WRITE :
                VWK_PAY_AMOUNT,
                WK_10,
                WK_11.
       WRITE:/.
      BSEG-KOART  = 'X'.                   " &#12501;&#12521;&#12464;&#65306;&#35531;&#27714;&#37329;&#38989;&#12434;&#20986;&#21147;
      LOOP AT ITAB_OUTPUT_ITEMS WHERE LIFNR = ITAB_LIFNR-LIFNR
                                AND   DTYPE = 5.          " &#21306;&#20998;&#65306;5
        BSEG-SGTXT   =  ITAB_OUTPUT_ITEMS-SGTXT.          " &#26126;&#32048;&#12486;&#12461;&#12473;&#12488;
        GLT0-KSLVT   =  ITAB_OUTPUT_ITEMS-DMBTR * WK_RATIO.     " &#37329;&#38989;
        TGSBT-GTEXT  =  ITAB_OUTPUT_ITEMS-GTEXT.              BKPF-BELNR   =  ITAB_OUTPUT_ITEMS-BELNR.         
       SUBNO = SUBNO + 1.
       VSUBNO = SUBNO.
       DATAKBN = 2.
       VDATAKBN = DATAKBN.
       VGLT0-KSLVT = GLT0-KSLVT.
       VBIKKO = TGSBT-GTEXT.
       VBELNR = BKPF-BELNR.
       VSGTXT1 ='&#35531;&#27714;&#37329;&#38989;:'.
       CLEAR VRECORD.
      CONCATENATE  VSGTXT1 BSEG-SGTXT INTO VSGTXT.
      CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
    VGLT0-KSLVT VBIKKO VBELNR INTO VRECORD SEPARATED BY ','.
      TRANSFER VRECORD TO E_FILE.
       WRITE :/ VPAGENO,VSUBNO,VDATAKBN,'&#35531;&#27714;&#37329;&#38989;:', VSGTXT, VGLT0-KSLVT,
                VBIKKO,VBELNR.
      ENDLOOP.
      CLEAR: BSEG-SGTXT,GLT0-KSLVT,BKPF-BELNR.
    LOOP AT ITAB_OUTPUT_ITEMS WHERE LIFNR = ITAB_LIFNR-LIFNR
                                AND   DTYPE = 6.          " &#21306;&#20998;&#65306;6
        BSEG-SGTXT   =  ITAB_OUTPUT_ITEMS-SGTXT.          " &#26126;&#32048;&#12486;&#12461;&#12473;&#12488;
        IF  ITAB_OUTPUT_ITEMS-SHKZG  =  CNS_CREDIT.       " &#37329;&#38989;
          GLT0-KSLVT  =  ITAB_OUTPUT_ITEMS-DMBTR * WK_RATIO.
        ELSEIF  ITAB_OUTPUT_ITEMS-SHKZG  =  CNS_DEBIT.
          GLT0-KSLVT  =  ITAB_OUTPUT_ITEMS-DMBTR * WK_RATIO * -1.
        ENDIF.
      TGSBT-GTEXT  =  ITAB_OUTPUT_ITEMS-GTEXT.          " &#20107;&#26989;&#38936;&#22495;&#12486;&#12461;&#12473;&#12488;
      BKPF-BELNR   =  ITAB_OUTPUT_ITEMS-BELNR.          " &#20253;&#31080;&#30058;&#21495;
      SUBNO = SUBNO + 1.
      VSUBNO = SUBNO.
      DATAKBN = 3.
      VDATAKBN = DATAKBN.
      VGLT0-KSLVT = GLT0-KSLVT.
      VBIKKO = TGSBT-GTEXT.
      VBELNR = BKPF-BELNR.
      VSGTXT1 ='&#30456;&#27578;&#37329;&#38989;:'.
      CLEAR VRECORD.
      CONCATENATE  VSGTXT1 BSEG-SGTXT INTO VSGTXT.
      CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
      VGLT0-KSLVT VBIKKO VBELNR INTO VRECORD SEPARATED BY ','.
      TRANSFER VRECORD TO E_FILE.
    concatenate vpageno vsubno vdatakbn
      WRITE :/ PAGENO,SUBNO,DATAKBN,'&#30456;&#27578;&#37329;&#38989;',BSEG-SGTXT, GLT0-KSLVT,
             TGSBT-GTEXT, BKPF-BELNR.
      ENDLOOP.
       CLEAR VRECORD.
    *Insert empty line.
      TRANSFER EMPTYREC TO E_FILE.
      DATAKBN = 3.
      VDATAKBN = DATAKBN.
      SUBNO = SUBNO + 1.
      VSUBNO = SUBNO.
      VSGTXT ='&#28304;&#27849;&#37329;&#38989;'.
      VDMBTR = BSID-DMBTR.
      CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
      VDMBTR INTO VRECORD SEPARATED BY ','.
      TRANSFER VRECORD TO E_FILE.
      WRITE :/ PAGENO, SUBNO,DATAKBN, ITAB_LIFNR-LIFNR,ITAB_LIFNR-NAME2,
             P_PAY_T,'&#28304;&#27849;&#37329;&#38989;', BSID-DMBTR.
      CLEAR: VDMBTR, VSGTXT, VRECORD.
      SUBNO = SUBNO + 1.
      VSUBNO = SUBNO.
      VSGTXT = '&#37109;&#36865;&#26009;'.
      VDMBTR = BSAD-DMBTR.
      CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
      VDMBTR INTO VRECORD SEPARATED BY ','.
      TRANSFER VRECORD TO E_FILE.
      WRITE :/ PAGENO, SUBNO,DATAKBN,ITAB_LIFNR-LIFNR,ITAB_LIFNR-NAME2,
             P_PAY_T,'&#37109;&#36865;&#26009;', BSAD-DMBTR.
      CLEAR: VDMBTR, VSGTXT, VRECORD.
      SUBNO = SUBNO + 1.
      VSUBNO = SUBNO.
      VSGTXT = '&#25391;&#36796;&#12415;&#25163;&#25968;&#26009;'.
      VDMBTR = BSEG-DMBTR.
      CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
      VDMBTR INTO VRECORD SEPARATED BY ','.
      TRANSFER VRECORD TO E_FILE.
      CLEAR: VDMBTR, VSGTXT, VRECORD.
      WRITE :/ PAGENO,SUBNO,DATAKBN,ITAB_LIFNR-LIFNR,ITAB_LIFNR-NAME2,
            P_PAY_T,'&#25391;&#36796;&#12415;&#25163;&#25968;&#26009;',BSEG-DMBTR.
    *&#12381;&#12398;&#20182;&#12398;&#25903;&#25173;&#12356;&#12398;&#20966;&#29702;
      SUBNO = SUBNO + 1.
      VSUBNO = SUBNO.
      VSGTXT = '&#12381;&#12398;&#20182;&#12398;&#25903;&#25173;&#12356;'.
      VDMBTR = GLT0-TSL05.
      CONCATENATE VPAGENO VSUBNO VDATAKBN VCODE VNAME2 VPAYDAT VSGTXT
      VDMBTR INTO VRECORD SEPARATED BY ','.
      TRANSFER VRECORD TO E_FILE.
      WRITE :/ PAGENO,SUBNO,DATAKBN,ITAB_LIFNR-LIFNR,ITAB_LIFNR-NAME2,
            P_PAY_T, '&#12381;&#12398;&#20182;&#12398;&#25903;&#25173;&#12356;',GLT0-TSL05.
                                     glt0-tsl05.
    ULINE.
    CLEAR: VREC, VRECORD,VCODE,VNAME2,VPAYDAT,VSGTXT,VSGTXT1,VKINGAKU.
    CLEAR: VBIKKO,VBELNR,VDMBTR,VGLT0-KSLVT,VGLT0-TSL01,VGLT0-TSL02.
    CLEAR: VGLT0-TSL03,VGLT0-TSL04,VGLT0-TSL05,VKIN,VTEGA,VWK_PAY_AMOUNT.
    ENDFORM.

  • How continuously write data to a txt file

    hello, 
    first of all, sorry for bad English, but I have a problem to continuously write data to the txt file.... I have one 2D array with values of some function and based on 2 sliders (values of the sliders) i want to interpolate value using bilinear method... and after that value of the sliders, interpolated value, and value of the nearest points i wish to write to txt file ... for every 2-3 seconds perhaps it would be ideal to be formated as :: 
    x   y   f     f1   f2   f3   f4
    but... first i have problem with writing data, because every time it deletes old data and just write new one and it's not horizontal... I'm very very new at this (it is obvious) and any help will be very appreciative  
    thanks  
    Solved!
    Go to Solution.
    Attachments:
    Proba.vi ‏21 KB

    Hi there,
    May I suggest you start with the LabVIEW tutorial?  Or perhaps this one?
    I say that because 1) you said you're new at this, and these tutorials are great for getting started; and 2) you don't seem to understand the concept of dataflow.
    A structure, such as a loop or subVI or function, cannot start executing until it has all of its inputs available.  Therefore, the loop which contains your file write (bottom loop) cannot execute until your top loop is done executing, because it depends on inputs from your top loop and those inputs aren't available until the top loop is finished.  Thus, your file will contain only the data from your final top loop execution.  You might be thinking that your loops are executing in parallel.  They are not.  Your file loop is executing after your data loop has finished...that is to say, your file loop executes exactly once, after you press your stop button.
    You can do two things here to fix that:
    1.  You can move your file write into the top (data) loop. (probably easier for now)
    2.  You can use a queue to transfer the data from your top (data) loop into your bottom (file write) loop. (more complex, but a better idea in the long run)
    One other thing.  Move the "open file" function outside the loop.  Opening and closing the file in each loop iteration will cause problems.  Open the file once.  Write to it in each loop iteration.  Close it when you're done.  Like this:
    Note that this is not complete code...you need to provide the data to write.  This is just to show you how to set up a continuous file write.
    Ok, start with the tutorials and we'll go from there. 

  • Write / read objects to/from File

    Hello,
    I have a problem with the writing and reading objects to/from a file.
    So what excatly I'm trying to is:
    I have a class Data. A thread creates constantly (until some limit) objects of this class Data.
    Once an object is created, is placed in a buffer (I wrote my own class DataBuffer extention of LinkedList).
    I have a limit on this buffer, so when the limit is reached, another thread starts getings objects from the buffer, writes them on the disk and removing them from the buffer.
    I'm putting the object always on the "top" and I'm reading them and removing always from the "bottom" of the buffer (FIFO).
    For writing the objects Data to the file, I'm using a FileOutputStream and ObjectOutputStream:
    I have something like that:
    FileOutputStream fos = new FileOutputStrea("file_name");
    ObjectOutputStream oos = new ObjectOutputStream(fos);after that I have this:
    while(size > i ){
                        try {
                             Data d = buff.getData();
                             //write to File
                             oos.writeObject(buff.getData());
                             oos.flush();
                             buff.removeData();
                             System.out.println("written data " + d);
                             i++;
                        } catch (IOException e) {
                             e.printStackTrace();
                   }here size is the limit for the buffer.
    So, when the size is equal to the total number of objects that were created and placed in the buffer, I have no problems with the writing/reading from the file.
    But if size is equal, for example, to the half of the total number of objects that were created, I have a problem.
    A more detailed exmple is:
    10 objects were created, the 10 objects were places to the buffer, a test was made and all the objects were written on the disk -> writing and reading are OK.
    if 10 objects were created, and I want to write 5 objects, and after that more 5, the first thing I remarqued is that the size of the file is different from the size of the file created by the first method. Second thing is when I'm reading from the file I can read only 5 objects and after that I have this exception:
    java.io.StreamCorruptedException : invalid type code : AC
    So ... is anyone has an idea why I have this problem?
    PS. For reading from the file I'm using another thread that executes this code:
    fis = new FileInputStream(readFile);
                        ois = new ObjectInputStream(fis);
                        while(true){
                             try{
                                  Data d = (Data)ois.readObject();
                                  System.out.println("data read " + d); //here I'm displaying the object that was read
                                  buff.putData(d);
                             }catch(EOFException e){
                                  break;
                        ois.close();
                        fis.close();
                   }catch (FileNotFoundException e) {
                        e.printStackTrace();
                   }catch(IOException e){
                        e.printStackTrace();
                   }catch (ClassNotFoundException e) {
                        e.printStackTrace();
                   }Regards,
    Anton
    PS. At present I'm writing first all the Data objects, and after that I'm trying to read from the file.
    Edited by: anton_tonev on Oct 5, 2007 4:14 AM

    Hello again :)
    Finally I found the solution :)
    In fact it is important to not to close the FileOutputStream and ObjectOutputStream until all the data was written on the disk.
    What I mean:
    in the begining of the program you have to open these two streams and write down the data that comes from somewhere.
    But you musn't close these streams before the final writing on the disk.
    It must look like this:
    1 Open file stream & opent object stream
    2 you're writing your all objects: one by one; 10 by 10 or as you wish ... but after each writing down you don't close the streams
    3 you already finished with the writing, (the end of your program), now you can close the streams.
    Unfortunatly I don't know why if I write the data and close the stream every time, after that it is impossible to append new data (with reopen the file)

  • How read/write matlab style WAV sound file?

    The supplied LabVIEW WAV read/write VIs require fixed sampling rates (like 8000, 11025, 22050, 44100), and use integer data (so the waveforms take on large +/- integer values).
    I need to read/write WAV files that are like those used in Matlab with its wavread and wavwrite functions. Those can use ANY sample rate, and the waveforms have decimal values between -1 and +1.
    Could someone suggest either how to directly write these standard WAV files with an existing VI, or how to write my own VI to do this?
    Thanks in advance.

    That's a great help! Thanks. I have made the changes to the supplied NI VIs so that any rate can be used. The new read/write VIs are attached and seem to work ok.
    Best,
    F
    Attachments:
    Snd_Read_Wave_File.vi ‏128 KB
    Snd_Write_Wave_File.vi ‏110 KB

  • How to write XI output to PDF file

    when we were  trying to do simple file to file scenario, I wanted to read a text file and write it in to pdf file format.The pdf file gets created but it show error(not supportd file type or file corrupted).
    Please help me to know whether pdf format is supported by XI file adapter.If yes, then how to convert the default XML ouptut to pdf format.
    Thanks in Advance,
    Regards
    Rashmi

    Hi,
    The following links will help you:
    http://www.devx.com/xml/Article/16430/0/page/2
    http://www.apache.org/dyn/closer.cgi/xml/fop
    Regards,
    Sridhar

  • How to write live video to .flv file

    We have an application that sends a live stream to offices in
    different locations. We'd like to capture that stream at the
    receiving end and write it to an .flv file so those who couldn't
    make the live broadcast can see the video on demand.
    Can anyone point me to a link that describes how to capture a
    live audio/video stream with AIR and write it to a local file store
    on the receiving end? We want to store the files remotely rather
    than using a central file store. I've seen how to write text files
    but not .flv's.
    Thanks for any direction you can provide.
    Steve

    There are two solutions here that I see, but one is probably more reasonable than the other.  Without the use of a streaming media server, you can't really record video/audio.  However, the FLV spec is open source and you can accomplish a "recording" by writing bitmap data bytes to a flv file (using the open source spec).  This won't capture the audio though, and you can't do that without a streaming server.  Also, if you're recording long videos, chances are the writing will either make your application unresponsive/crash it, or the saving time if you broke it down to manageble chuncks would take forever.
    The second option, probably what you want, is a streaming server.  Whether it be Red5, Wowza, FMS, etc, you'll be able to accomplish what you want, and it should be fairly easy.  All be it much more expensive.  For what you're describing though, recording live streams, it is probably the most likely approach.

  • How to write a inpurstream to a file.

    I have a InputStream object( aRuntime.exec()).
    I want to write this inoutstream to a file.
    Which is the best way to do it.
    Please help.

    Please consider the following code snippet
    use object input stream to do it
    String urcustomfilename ="some location directory"
    FileOutputStream out = new FileOutputStream(urcustomfilename);
    ObjectOutputStream s = new ObjectOutputStream(out);
    s.writeObject(key);
    s.flush();
    s.close();
    Please dont forget to flush and close the connection
    Regards
    Karthik

  • How to write dbms_out traces into a file (in a shell script)?

    I'm afraid this is a shell scripting question:
    I have the following lines in a script:
    ls $salida/EXAR* | while read FILE
    do
    sqlplus -s user@isntance/password << EOF
    set serveroutput on size 1000000
    set feedback off
    --set trimspool on
    var p_out_result_nv number
    var p_out_DescError_SV varchar2(4000)
    var p_out_Traza_SV varchar2(4000)
    var p_Fich_Entrada varchar2(4000)
    --spool $mi_fich_log
    begin
    :p_Fich_Entrada := replace(('$FILE'),('$salida/'),'');
    dbms_output.put_line('Tratando archivo: '||:p_Fich_Entrada);
    :p_out_result_nv := 0;
    SJPAMIOB.SJPRPRIN('01',:p_Fich_Entrada,:p_Fich_Entrada,'EXSJ_ENTRADA','EXSJ_SALIDA',
    :p_out_result_nv,:p_out_DescError_SV,:p_out_Traza_SV);
    end;
    --spool off
    exit :p_out_result_nv
    EOF
    How can I write all dbms_output.put_line in a file?
    Thanks in advance.

    you can use the package utl_file.
    for this you either
    - need a directory object in the database which points to the folder where your file is located you want to write to:
    CREATE DIRECTORY lutz_dir AS ´/home/oracle/UTL_FILE_DIR´;
    You will need create any directory privilege for this.
    or
    - you must have the init.ora parameter UTL_FILE_DIR set to the location.
    Regards,
    Lutz

  • How to write attributes to a .stp file in Adobe 3D Reviewer?

    Hello All,
    I am trying to import a .stp file into Adobe 3D Reviewer and I need to write attributes to this file. I am using VB (.NET 4.0) for this purpose.
    I imported the Adobe 3D Reviewer Object Library reference and am trying to make use of the AddAttribute method of the GeomItem class to write the attributes. However, I am unable to instantiate the GeomItem class. I get this error : 'Adobe3DReviewer.GeomItemClass.Friend Sub New()' is not accessible in this context because it is 'Friend'. I am not sure how else can I access this class? Also, in the object browser GeomItem shows up as a class but in Intellisense it shows up as an interface.
    Can anyone shed some light on how to resolve this error or make use of any other method to write the attributes and their values in the Adobe 3D Reviewer? Also, if anyone can point to some documentation related to this stuff it would be great!
    Thanks in advance.

    different possibilities:
    - search this forum and find your question answered at least a dozen times,
    - read the DOM / SAX and XSLT tutorials available in this web site.

Maybe you are looking for