Write.out to data.dat file

Am new to all this an pretty sure this stuff is basic but god its doing my head in....
Basically i`ve got to write a program in java that can write data to a data.dat file. Thats fine. I`ve done that.
Thing is when you enter the data it replaces the top line of the data.dat file with the new data rather than simply adding the new data to the file.
Please help guys

ok...the method for actually entering the new data (its for an address/contacts database) is here...
public static void insertRecord(String temp2, String temp1, String temp3, String temp4, int number_of_records)
     number_of_records = number_of_records + 1;
               // increment record count as we are adding another one      
               for (int i=0; i < number_of_records - 1; i++)
                    // here we see if the surname of the new record input is lower than the ones already in the arrays and also less than the next one after that
                    if(temp2.compareToIgnoreCase(lastName) > 0 && temp2.compareToIgnoreCase(lastName[i+1]) < 0)
                    int insertPoint = i;
               // we then assign the new record data into the arrays "in the correct place"
                    lastName[i] = temp2;
                    firstName[i] = temp1;
                    telNumber[i] = temp3;
                    emailAddress[i] = temp4;     
and the method to actually write it to the data.dat file (or in this case a new file of my choice so i can compare the original with the new one) is...
public static void write_out_file(int number_of_records, String filename)
//public static void write_out_file(int no_of_records, String filename)
          PrintStream write_out;
          int counter;
          try
               // Create new file
               write_out = new PrintStream(new File(filename));
               // Output all records
               for(counter = 0; counter < number_of_records; counter++)
                    // Output a record
                    write_out.print(lastName[counter]);
                    write_out.print(",,");
                    write_out.print(firstName[counter]);
                    write_out.print(",,");
                    write_out.print(telNumber[counter]);
                    write_out.print(",,");
                    write_out.println(emailAddress[counter]);
               // Close file
               write_out.close();
          catch (FileNotFoundException e)
               e.printStackTrace();

Similar Messages

  • How do I get firefox to write out homepages to pdf-files correctly

    2011-08-22
    I have been using Firefox for many years now. I like this browser better than Safari. However. I have a problem when I have connected to a homepage over the web and want to write the content out to a pfd-file. The pdf-file does sometimes contain only one page. The material is good enough for two or more pages of output. I have checked that using Safari browser. I´d like to continue using Firefox so please tell med what to do!
    Göran Stille
    [email protected]
    Computer Mac Powerbook G4
    Processor 1.67 GHz PowerPC G4
    Operative system OSX 10.5.8
    Firefox version 3.6.2

    "Google" is a search engine (website) and NOT (repeat: NOT) a PDF viewer. It can't and won't open PDFs in any real or imaginable way.
    Firefox added their own proprietary PDF viewer with version 20 - they're on 21 now. I'll be the first to admit "it sucks". You CAN'T fill in PDF forms with it, and you can't email them from the page like with Opera, Safari or Chrome (which use the reader plug-in still).
    Unfortunately, the ONLY option you have now that they've added it and killed the ability for the Reader plug-in to work with Firefox, is Tools>Options>Applications - select Portable Document Format(PDF) and choose "Use Adobe Reader (Default)". What that will do is FORCE Firefox to download the PDF instead of opening it in their terrible PDF viewer in the browser window.
    Or... use one of the other browsers I mentioned. They're all free.

  • Can Oracle write out a sorted export file

    I thought I read that a version of exp sorts data using something like an ORDER BY clause. But I can't find any documentation for that. Does anyone know if 9i or 10g does this?
    Thanks,
    Jerie

    http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10825/dp_export.htm#sthref148

  • What is the best way to write 10 channels of data each sampled at 4kHz to file?

    Hi everyone,
    I have developed a vi with about 8 AI channels and 2 AO channels... The vi uses a number of parallel while loops to acquire, process, and display continous data.. All data are read at 400 points per loop interation and all synchronously sampled at 4kHz...
    My questions is: Which is the best way of writing the data to file? The "Write Measurement To File.vi" or low-level "open/create file" and "close file" functions? From my understanding there are limitations with both approaches, which I have outlines below..
    The "Write Measurement To File.vi" is simple to use and closes the file after each interation so if the program crashes not all data would necessary be lost; however, the fact it closes and opens the file after each iteration consumes the processor and takes time... This may cause lags or data to be lost, which I absolutely do not want..
    The low-level "open/create file" and "close file" functions involves a bit more coding, but does not require the file to be closed/opened after each iteration; so processor consumption is reduced and associated lag due to continuous open/close operations will not occur.. However, if the program crashes while data is being acquired ALL data in the buffer yet to be written will be lost... This is risky to me...
    Does anyone have any comments or suggestions about which way I should go?... At the end of the day, I want to be able to start/stop the write to file process within a running while loop... To do this can the opn/create file and close file functions even be used (as they will need to be inside a while loop)?
    I think I am ok with the coding... Just the some help to clarify which direction I should go and the pros and cons for each...
    Regards,
    Jack
    Attachments:
    TMS [PXI] FINAL DONE.vi ‏338 KB

    One thing you have not mentioned is how you are consuming the data after you save it.  Your solution should be compatible with whatever software you are using at both ends.
    Your data rate (40kS/s) is relatively slow.  You can achieve it using just about any format from ASCII, to raw binary and TDMS, provided you keep your file open and close operations out of the write loop.  I would recommend a producer/consumer architecture to decouple the data collection from the data writing.  This may not be necessary at the low rates you are using, but it is good practice and would enable you to scale to hardware limited speeds.
    TDMS was designed for logging and is a safe format (<fullDisclosure> I am a National Instruments employee </fullDisclosure> ).  If you are worried about power failures, you should flush it after every write operation, since TDMS can buffer data and write it in larger chunks to give better performance and smaller file sizes.  This will make it slower, but should not be an issue at your write speeds.  Make sure you read up on the use of TDMS and how and when it buffers data so you can make sure your implementation does what you would like it to do.
    If you have further questions, let us know.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • Easiest way to write XMP data or files into a PDF file

    Hi,
    I wrote a little Adobe Air application, which is intended to generate XMP files for being imported into PDF files. Now I'm searching for the most efficient solution to import these XMP files. I'd be happy if I could select a PDF file from my Adobe Air application and write the metadata into the file, but I didn't find any library to this. Another option is something like a hotfolder. I try to avoid to import these files one by one. Could someone please give me a hint?
    I'd be very glad!
    Thank you beforehand!
    Stefan

    Hi,
    Thanks for your suggestion.
    My experience is more in Postgresql, sql server and ms access. So I can handle sql command better than java.
    According to your suggestion, I come out following design.
    Design:
    1. Use SQL Developer to developer a copy stored procedure.
    - The store procedure will copy ONE row of main data and data in related data table.
    - use database link to access remote database.
    - handle transaction and return error message if got error.
    - update data if the data already copied into destination database.
    2. A java program perform following tasks:
    a. Use jdbc install the stored procedure in #1 into database by "CREATE OR REPLACE FUNCTION ..."
    b. load copy data list from a file.
    c. a loop to call installed stored procedure. Pass one main row per time into stored procedure.
    d. print each main row copy result to stdout in the loop and stop if error happened.
    So, I just need to pass the java program to operator.
    Please tell me if you have any better idea or easier way to implement. Maybe, another possible solution is use shell script to execute sql command in sqlplus. :)
    Thanks,
    Regards,
    Hing Cheow Yong

  • Write RAW buffer (binary data) to OS file

    Hi there,
    It is easy to insert BLOB data into a BLOB-column of a table from a BFILE. But how can a do the other way around? That means:
    Read the BLOB (maybe into a variable 'buffer RAW(...)') and write it into a binary file? As I know, the UTL_FILE package only supports ascii files.
    The following demo example works to display the raw-data on the screen:
    CREATE OR REPLACE PROCEDURE displayLOB_proc IS
    Lob_loc BLOB;
    Buffer RAW(255);
    Amount BINARY_INTEGER := 255;
    Position INTEGER := 1;
    BEGIN
    /* Select the LOB: */
    SELECT Photo INTO Lob_loc
    FROM testblob WHERE id = 1;
    /* Opening the LOB is optional: */
    DBMS_LOB.OPEN (Lob_loc, DBMS_LOB.LOB_READONLY);
    LOOP
    DBMS_LOB.READ (Lob_loc, Amount, Position, Buffer);
    /* Display the buffer contents: */
    DBMS_OUTPUT.PUT_LINE(utl_raw.cast_to_varchar2(Buffer));
    Position := Position + Amount;
    END LOOP;
    /* Closing the LOB is mandatory if you have opened it: */
    DBMS_LOB.CLOSE (Lob_loc);
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    DBMS_OUTPUT.PUT_LINE('End of data');
    END;
    What should be inserted instead of DBMS_OUTPUT.PUT_LINE(...).
    Please help
    Peter

    >I have discovered that I just posted the same question.
    Please annote your other post as such.
    >Does DBMS_UTIL 9.2 run under Oracle 8i?
    UTL_FILE (not DBMS_UTIL), and 9.2 = Oracle9i Database Release 2. So, no. You will need to implement an external procedure via c or java to get you home with 8i. Search this forum (as best as you can) for the multitudes of such solutions.
    >Where can I locate some of the sameple code that you mention?
    I have none handy, yet. You can read all about it @ http://tahiti.oracle.com
    Michael O'Neill
    Publisher of the PigiWiki
    clever-idea.com

  • I want to run my program with continuous aquisition and write data to file when a button is pressed and get the most recent samples from the DAQ board.

    This is an update to a question I asked earlier. I am still trying to solve the problem. I have included a zip file with a library file. The file to open in pj_pushbutton.vi. I have placed comments explaining the issues and problems in this vi and the subvi's.
    When I push my button to write the data to file I think it is writing the data that has already been stored in the buffer and writing to file all at once. I want the data that is taken from the DAQ board from the time that I press the Write File button. How do I do this?
    Attachments:
    pj_pushbutton.zip ‏692 KB

    Hi,
    1. In AI read, you need to set the Read/Search option to "Relative to End of Data".
    2. Next you should not start AI Read VI until you press the Write to File. I am attaching an example VI below. Please see if it helps.
    Regards,
    Sastry V
    applications Engineer
    National Instruments
    Attachments:
    MostRecentAcquiredData.vi ‏97 KB

  • How to write data to file Java ME cldc 1.1 midp 2.0?

    I newly in java me, please help me.
    I make project in NetBeans 7.0.1. and use cldc 1.1 midp 2.0.
    I want to write data to the file.
    How can I do it?
    I try to use FileOutputStream. But it don't exists in java.io
    NetBeans shows me only this list of classes and interfaces in java.io:
    ByteArrayInputStream, ByteArrayOutputStream, DataInput, DataInputStream, DataOutput, DataOutputStream, InputStream, InputStreamReader, OutputStream, OutputStreamWriter, PrintStream, Reader, Writer.
    Why it so short?
    And how I can write data to file?
    Data can be array of bytes (byte[]) or Object it better.

    You must use JSR 75: FileConnection. Please check the following article "Getting Started with the FileConnection APIs":
    http://developers.sun.com/mobility/apis/articles/fileconnection/
    Be sure to use FileSystemRegistry.listRoots().
    And welcome to Java ME development. :)

  • How to write one row of data at a time to "Write to File"

    I am trying to write 10 parameters to the LV "Write to File". This is for just one row at a time. This happens evertime I get a failure in my test routine. I am not quite sure how to accomplish this task. If I get another failure I write one row again. I testing 4 DUTS at a time so I write this row of data to each file. I am sure it is very simple.
    Thanks
    Philip

    Assuming your 10 parameters are an numeric array with 10 elements,  use "write to spreadsheet" file with append set to true. (... and if they are scalars, built the array first ).
    LabVIEW Champion . Do more with less code and in less time .

  • How to get the validity of the socket before writes out datas?

    I should keep the socket which created before and send/recieve datas several times,and the socket would be closed by other side after minites,
    the question is
    How can I get the validity of the socket before writes out datas?

    If I understand well yor concern...
    There is no way to know if a socket is still connected without using (i.e reading /writing on) it.
    That's the way it works on C API layer, so it should not be defferent in Java.
    For a good understanding of how TCP/IP works, if C code is OK for you, the best are Richard Stevens books.... (IMHO)

  • [Flat File Destination [220]] Error: Failed to write out column name for column "Column 2"

    I am using SSIS to extract fixed width data into a flat file destination and I keep getting below error. I have tried almost everything in this forum but still no solution. can anyone help me out to solve this problem.
    [Flat File Destination [220]] Error: Failed to write out column name for column "Column 2".
    [SSIS.Pipeline] Error: component "Flat File Destination" (220) failed the pre-execute phase and returned error code 0xC0202095
    Thanks

    Hi Giss68,
    Could you check the Advanced tab of the Flat File Connection Manager to see whether the InputColumnWidth and the OutputColumnWidth properties of the Column2 has the same value? Please refer to the following link about the same topic:
    http://stackoverflow.com/questions/10292091/how-do-i-fix-failed-to-write-error-while-exporting-data-to-ragged-right-flat-fil 
    If it doesn’t work, please post the sample data and the advanced settings of Column2 for further analysis.
    Regards,
    Mike Yin
    If you have any feedback on our support, please click
    here
    Mike Yin
    TechNet Community Support

  • Best way to record 50 kS/s data to file

    I am trying to read data from a DAQ at a sampling rate of 50 kS/s and record it to a file. My application needs to run for at least a few hours. Initially, I tried a producer-consumer loop pattern with a Write to Measurement File Express VI, but it wrote the data too slowly, and my queue filled up. Now I am trying to use the Write to Spreadsheet File VI with or without a producer-consumer loop pattern (see attached VIs). Both seem to write data to file, but neither writes the number of datapoints I would expect (both have far fewer datapoints).
    What is the best way to write this data to file? This seems like a basic question, so if it has already been discussed at length in another forum, or if there are examples of it which someone could direct me to, that would also be appreciated.
    Thank you!
    Solved!
    Go to Solution.
    Attachments:
    Record Data 8-7-13 with Producer Consumer.vi ‏54 KB
    Record Data 8-7-13 without Producer Consumer.vi ‏48 KB

    I agree that TDMS is probably the best way to go for fast data streaming.
    I also want to point out that you can read TDMS files with some spreadsheet software. This makes it easier to manage and provides a method for human readability.
    Add in tool for Open Office Calc
    http://www.ni.com/white-paper/6849/en
    Add in tool for MS excel
    http://www.ni.com/white-paper/4906/en
    Jeremy P.
    Applications Engineer
    National Instruments

  • How can I write a read a data on a SmartCArd

    Hi everyone...
    I would like to know. how I can write and read a data on a SmartCard maybe through a file(IO)
    could you helpme please??
    Thanks a lot...
    Marcos

    Try this mate
    package com.reader;
    import java.util.List;
    import javax.smartcardio.Card;
    import javax.smartcardio.CardChannel;
    import javax.smartcardio.CardException;
    import javax.smartcardio.CardTerminal;
    import javax.smartcardio.CardTerminals;
    import javax.smartcardio.CommandAPDU;
    import javax.smartcardio.ResponseAPDU;
    import javax.smartcardio.TerminalFactory;
    import com.sun.javacard.apduio.Apdu;
    * @author ic008391
    public class Connector extends Thread
         * @param args
         * @param args
         public static void main(String[] args)
              List<CardTerminal> lct = null;
              Card crd = null;
              TerminalFactory tf = TerminalFactory.getDefault();
              CardTerminals cts = tf.terminals();
              CardChannel cch = null;
              try
                   //create APDU Command
                   Apdu apdu = new Apdu();
                   apdu.command[Apdu.CLA] = (byte) 0X00;
                   apdu.command[Apdu.INS] = (byte) 0XA4;
                   apdu.command[Apdu.P1] = (byte) 0X04;
                   apdu.command[Apdu.P2] = (byte) 0X00;
                   //apdu.command[Apdu.P3] = (byte) 0X0a;
                   byte[] data = {(byte)0xa0, (byte)0x0, (byte)0x0, (byte)0x0, (byte)0x62, (byte)0x3, (byte)0x1, (byte)0xc, (byte)0x6, (byte)0x1, (byte)0x7F};
    //wallet 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xC:0x6
    // select 0x00 0xA4 0x04 0x00 0x0a 0xa0 0x0 0x0 0x0 0x62 0x3 0x1 0xc 0x6 0x1 0x7F
                   lct = cts.list();
                   System.out.println(lct);
                   CardTerminal ct = lct.get(0);
                   crd = ct.connect("T=0"); //Or "T=1"
                   javax.smartcardio.ATR atr = crd.getATR();
                   byte i[] =atr.getBytes();
                   for (int n = 0; n < i.length; n++) {
              int x = (int) (0x000000FF & i[n]); // byte to int conversion
              String s = Integer.toHexString(x).toUpperCase();
              if (s.length() == 1) s = "0" + s;
              System.out.print(s + " ");
                   System.out.println("");
                   System.out.println("ATR"+(atr.getHistoricalBytes()).toString());
                   System.out.println("ATR"+atr.toString());
                   cch = crd.getBasicChannel();
                   sleep(1000);
                   ResponseAPDU r;
                   //r = cch.transmit(new CommandAPDU(apdu.getCommand()));
                   r = cch.transmit(new CommandAPDU(0,164,4,0,data));
                   System.out.println(apdu);
                   System.out.println(r);
                   //Get Balance
                   //0xB0 0x50 0x00 0x00 0x00 0x02;
                   r = cch.transmit(new CommandAPDU(176,80,0,0));
                   System.out.println(r);
                   //cch.close();
              catch (CardException e)
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              catch (InterruptedException e)
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              finally
                   try
                        crd.disconnect(true);
                   catch (CardException e)
                        // TODO Auto-generated catch block
                        e.printStackTrace();
    }

  • Best way to stream lots of data to file and post process it

    Hello,
    I am trying to do something that seems like it should be quite simple but am having some difficulty figuring out how to do it.  I am running a test that has over 100 channels of mixed sensor data.  The test will run for several days or longer at a time and I need to log/stream data at about 4Hz while the test is running.  The data I need to log is a mixture of different data types that include a time stamp, several integer values (both 32 and 64 bit), and a lot of floating point values.  I would like to write the data to file in a very compressed format because the test is scheduled to run for over a year (stopping every few days) and the data files can get quite large.  I currently have a solution that simply bundles all the date into a cluster then writes/streams the cluster to a binary file as the test runs.  This approach works fine but involves some post processing to convert the data into a format, typically a text file, that can be worked with in programs like Excel or DIAdem.   After the files are converted into a text file they are, no surprise, a lot larger than (about 3 times) the original binary file size.
    I am considering several options to improve my current process.  The first option is writing the data directly to a tdms file which would allow me to quicly import the data into DIAdem (or Excel with a plugin) for processing/visualization.   The challenge I am having (note, this is my first experience working with tdms files and I have a lot to learn) is that I can not find a simple way to write/stream all the different data types into one tdms file and keep each scan of data (containing different data types) tied to one time stamp.  Each time I write data to file, I would like the write to contain a time stamp in column 1, integer values in columns 2 through 5, and floating point values in the remaining columns (about 90 of them).  Yes, I know there are no columns in binary files but this is how I would like the data to appear when I import it into DIAdem or Excel.  
    The other option I am considering is just writing a custom data plugin for DIAdem that would allow me to import the binary files that I am currently creating directly into DIAdem.  If someone could provide me with some suggestions as to what option would be the best I would appreciate it.  Or, if there is a better option that I have not mentioned feel free to recommend it.  Thanks in advance for your help.

    Hello,
    Here is a simple example, of course here I only create one value per iteration in the while loop for simplicity. You can also set properties of the file which can be useful, and set up different channels.
    Beside, you can use multiple groups to have more flexibility in data storage. You can think of channels like columns, and groups as sheets in Excel, so you see this way your data when you import the tdms file into Excel.
    I hope it helps, of course there are much more advanced features with TDMS files, read the help docs!

  • Urgent!! Help me - Read formatted data from file

    Hi,
    I have a file which contains(line by line) :
    [0.0577, 0.0769, 0.0385, 0.0, 0.0]
    [0.0577, 0.1346, 0.0962, 0.0, 0.0]
    [0.0192, 0.0, 0.0577, 0.1154, 0.0962]
    How can i read the file line by line(exluded "[" and "]" symbols) and assign each line to an array?
    Thanks

    full code regarding readin/writing
    import java.net.*;
    import java.io.*;
    import java.util.*;
         public class FtpWrite {
                   static StringBuffer Data = new StringBuffer(20);
             public static void main(String[] args) throws Exception {
                   int jobNumber = 10006;
                   String dataOut = "Liam Charles Rangers";
                   URL ftpUrl = new URL("ftp://username:[email protected]/dataOutput.txt");
                           URLConnection conn = ftpUrl.openConnection();
                   conn.setDoOutput(true);
                           OutputStream out = conn.getOutputStream();
                   PrintWriter writer = new PrintWriter(out);
                           System.out.println("Writing to ftp");
                   writer.print(jobNumber);
                   writer.print('\t');
                   writer.print(dataOut);
                   writer.print('\n');
                           writer.close();
                   out.close();
                   String dataIn;
                   InputStream inFile = ftpUrl.openStream();
                   BufferedReader in = new BufferedReader(new InputStreamReader(inFile));
                   dataIn = in.readLine();
                   System.out.println("The data is" + dataIn);
                   in.close();
                     StringTokenizer parser = new StringTokenizer(dataIn);
                       while (parser.hasMoreTokens()) {
                             System.out.println(parser.countTokens());
                             processWord(parser.nextToken(),parser.countTokens());}
                   public static void processWord(String token, int position){
                   int jobNumber = 0;
                   System.out.println("in process word token = " + token + " at position" + position );
                   if (position == 3)
                        jobNumber = Integer.parseInt(token);
                   jobNumber = jobNumber * 2;
                   System.out.println(jobNumber);
                   if((position <3) && (position>=0))
                        Data.append(token);
                        Data.append(' ');
                   System.out.println("Data is " + Data);
    }this code has just been completed with a bit of help. I gave it to you warts and all.
    Jim

Maybe you are looking for

  • Using variable with the same name as field name?

    I have a complex proc where I have variables with the same name as field name used on a query. something like this: SELECT a.id_table WHERE a.id_table = id_table where the last id_table is a parameter sent to the proc: declare procedure myproc(id_tab

  • CAN'T RENAME PICTURE IN N97

    Hi friends, CAN'T RENAME PICTURE IN N97. I have recently bought a N97 (I have been using a N73 Music) and need help for this problem - After taking a still image / video (& before closing the camera cover - there is a option to rename it - max 31 to

  • Meta data not being imported

    Hi, I am using OBIEE 11. I have created an ODBC to a SQL database. I have created a new BI repository in the BI admin tool and chose the odbc as the data source. I selected all metadata types. When I click on the finish the database is in the physica

  • Backing up multiple drives using TimeMachine

    I currently only back up my internal drive on my iMac. I was thinking of also including one of my exteral drives as well. My question is, if I ever have to recover from a TimeMachine, how will that work? I assume backing up just the internal drive le

  • How to save an image to database and retreive from it.

    how to save an image retreived from an bytearray to database and retreive back the image from database....pls specify the steps and the query.