Write vectors to a file

HI,
I like to write a Vector-object with the objects in the vector to a file, sow I can open the file as I run the program next time.
Vector Muur;
public void writeVec()
Vector Muur = new Vector();
Muur.add(Muur.size-1, new Object());
//here I like to write Muur to a file named muur.ROb.
pubic void openVec()
//here I like to fill Muur with the data from muur.ROb
Do anyone know how to do this?
Every reaction is welcome.

If you read API Vector specification you will see that the class has it's own implementation of the method toString() that calls a method with the same name for each added object.
Add to the Vector objects of your own class and implement in this class the toString method as in the example below:
import java.util.Vector;
public class VecTest
public static void main (final String[] args)
Vector myVec = new Vector();
myVec.add(new Vecobj("1"));
myVec.add(new Vecobj("2"));
System.out.println(myVec.toString());
class Vecobj
String val;
public Vecobj(String myVal)
val = myVal;
public String toString()
return "Value:" + val;
}

Similar Messages

  • Help With Writing A Vector To A File

    hi
    i am having trouble writing a vector to a file
    Here is my code
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import javax.swing.filechooser.*;
    public class Save
         JFileChooser fc = new JFileChooser();
         public Save(JFrame par, mainCollection col)
         try
         ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream fc.getSelectedFile().getName()));
         out.writeObject(col.carCollection);
         for(int i = 0; i< col.carCollection.size();i++)
         Cars cd = (Cars)col.carCollection.elementAt(i);
         Vector v = cd.getModels();
         out.writeObject(v);
         }catch(FileNotFoundException e){System.out.println("not found");}
         catch(IOException e){System.out.println("IO" + e.getMessage());}
    Ok now the mainCollection col is from my other class mainCollection which has my main vector in it. This main vector contains car types which contain car models i.e. Ford which contains Falcon. What i need to do is copy the whole contents of vector over in one go to the file.
    With the code above i am getting IO Exception errors
    here is the errors
    �� sr java.util.Vector��}[�;� I capacityIncrementI elementCount[ elementDatat [Ljava/lang/Object;xp       ur [Ljava.lang.Object;��X�s)l  xp  
    {sr  java.io.NotSerializableException(Vx ��5  xr java.io.ObjectStreamExceptiond��k�9��  xr java.io.IOExceptionl�sde%��  xr java.lang.Exception��>;�  xr java.lang.Throwable��5'9w�� L
    detailMessaget Ljava/lang/String;xpt Cars
    Whatever all that means
    Thanks for your help, i'm really confused
    DaJavaLodown
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Remove the for loop.
    If you write the vector, it's content will be written too.
    hi
    i am having trouble writing a vector to a file
    Here is my code
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import javax.swing.filechooser.*;
    public class Save
         JFileChooser fc = new JFileChooser();
         public Save(JFrame par, mainCollection col)
         try
    ObjectOutputStream out = new
    = new ObjectOutputStream(new FileOutputStream
    fc.getSelectedFile().getName()));
         out.writeObject(col.carCollection);
    for(int i = 0; i<
    = 0; i< col.carCollection.size();i++)
    Cars cd =
         Cars cd = (Cars)col.carCollection.elementAt(i);
         Vector v = cd.getModels();
         out.writeObject(v);
    }catch(FileNotFoundException
    ion e){System.out.println("not found");}
    catch(IOException e){System.out.println("IO" +
    " + e.getMessage());}
    Ok now the mainCollection col is from my other class
    mainCollection which has my main vector in it. This
    main vector contains car types which contain car
    models i.e. Ford which contains Falcon. What i need to
    do is copy the whole contents of vector over in one go
    to the file.
    With the code above i am getting IO Exception errors
    here is the errors
    �� sr java.util.Vector��}[�;� I
    capacityIncrementI elementCount[ elementDatat
    [Ljava/lang/Object;xp       ur
    r [Ljava.lang.Object;��X�s)l  xp  
    {sr  java.io.NotSerializableException(Vx ��5  xr
    java.io.ObjectStreamExceptiond��k�9��  xr
    java.io.IOExceptionl�sde%��  xr
    r java.lang.Exception��>;�  xr
    java.lang.Throwable��5'9w�� L
    detailMessaget Ljava/lang/String;xpt Cars
    Whatever all that means
    Thanks for your help, i'm really confused
    DaJavaLodown

  • TS1717 unes, i have windows 8, i get the message, "the itunes Library .itl file is locked, on a locked disk, or you do not have write permission for this file.  how did this happen, how do i fix this?

    the message"The itun, library .itl file is locked, on a locked disk, or you do not have write permission for this file". i have windows 8. how why did this happen? how do i correct this and prevent another occurance?  I am able to access itunes on my i5, ipad, and my old i4 that i use solely as my ipod now. At the time  problem occurred, i was connected to ext hard drive that hold over 190GB music, to add to my library. I am now unable to add to my library using my laptop.  any advise/help is greatly appreciated!!

    I just had the same problem and was able to fix it after trying a couple of things I found after a search.
    The solution that worked for me:
    Find iTunes folder - it should be in C:\Program FIles (x86) or similar depending on your operating system
    Right click the entire folder (no need to open it) and click properties
    Click the security tab
    Click edit and highlight the user name under which you logged in.
    Click the box next to full in the allow column, which should check everything
    Click apply
    Open iTunes
    This worked for me.

  • How To Fix: "The iTunes Library.itl file is locked, on a locked disk, or you do not have write permission for this file."

    I can't reopen my iTunes after I have to force quit when it does not respond. I get this message:
    "The iTunes Library.itl file is locked, on a locked disk, or you do not have write permission for this file."
    I've read to do the solutions. I right clicked on both the iTunes and Music folder and went to info for each. On both the lock at the bottom of the Get Info was locked. All of my users including admin can read and write all files within those folders. They are even a shared folder. I clicked on the lock to unlock it, typed in my admin password, and went to the gear to apply to all files inside. After doing that I keep getting the saved message.
    I tried another way that I've found online to move my ituneslibrary folder to the desktop and then open my iTunes. In theory the iTunes is supposed to ask for where the iTunes library is. Once that is prompted you quit iTunes and drag the iTunes Library folder back to the folder from the desktop and reopen iTunes to apprently solve the problem. However, when I move the iTunes Library file to the desktop and try to reopne iTunes the icon just keeps bouncing and when I right click the application does not respond.
    This problem is only resolved if I restart/shut down my macbook pro which is a 15-inch Core 2 Duo with intel. It will be 5 years old in December. I currently have Lion and the latest iTunes 10.5. This problem started in late December. 

    If you hold down the option key when starting iTunes, it will allow you to select a library or create a new one.
    You can create a new one, and then add all of your iTunes music back in by simply dragging the old iTunes music file onto iTunes.
    There are more detailed instructions at http://support.apple.com/kb/HT1451#
    It will show you how to re-build your iTunes database file.

  • Write Access to a file in Tomcat server via J2me Midlet

    How to make write access to a file using midlet and HTTP connection?
    I have text file in the Tomcat server and I am able to read it with HTTP connection using emulator, but don't have idea how to make write access to the file. I'd like to write some text to the file.

    Thanks, but could you be more accurate. What methods should I use in the servlet and what methods in the midlet?
    Some links which concern this subject, would be nice too. I have tried with google, no success.

  • ITunes won't open, I get this message: The iTunes Library .itl file is locked, on a locked disk or you do not have write permission for this file.

    iTunes won't open.
    I get this message: The iTunes Library .itl file is locked, on a locked disk or you do not have write permission for this file.

    This may indicate a corrupt preference file with iTunes trying to open the wrong location. Try holding down shift as you launch iTunes then choose the correct file, normally <User's Music>\iTunes\iTunes Library.itl. See iTunes: How to open an alternate iTunes Library file or create a new one.
    tt2

  • HT1527 iphone wont open it says the itunes library.itl file is locked on a locked disk or you do not have write permission for this file. nothing l  do seems to help thanks

    Have tried to connect and sync my iphone 4 to my computer in itunes but this message keeps coming up The itunes Library .itl file is locked on a locked disk. or you do not have write permission for this file.

    I have tried both suggestions, unfortunately neither fixed this for me. Hoping there's another possible fix. Thanks in advance. 
    Empty/corrupt iTunes library after upgrade/crash and/or Repair security permissions for iTunes for Windows.

  • Data Acquisition - using local variables to write data to a file

    Hello,
    I am running a Data Acquisition vi (currently in LabVIEW 7.1 but soon to be updated to 8.2) that collects ~100 parameters of data from several sources contained in a while loop. The current configuration (which I did not write) uses very few subVIs and writes to ~100 local variables to store each parameter. It then reads all the local variables and builds an array of all the strings, converts then to a spreadsheet string, then uses the write characters to file function to append to a datafile. I am trying to clean things up and have came up with subVIs to collect the data from the following sources:
    8 serial port sources collecting btwn 8 and 20 parameters each
    ~15 thermocouple readings
    ~10 analog inputs
    ~20 parameters read off an ARINC 429 bus.
    I have come up with a subVI to read each of the sources and have placed the subVIs in the while loop. Each subVI outputs the data that it collects in array or cluster form. I was wondering how best to write each parameter to a CSV file at between 1 and 10 Hz. Should I write each subVI output to a LV and then read them off as was done before (the difference being that I have reduced the # of LVs to ~10 vs >100?
    I should add that precise timing is not that important, so if all the subVIs are not collecting simultaneously (which I understand that they won't be), it does not really matter.
    Thanks.

    Hi jilla,
    jilla wrote:
    What I think that you are saying is to turn the outputs of the 4 subVIs into inputs of a 5th subVI that writes to the data file. Correct?
    Yes.  It may sound like a fine-point, but I beileve it's better to create a VI specifically for formatting data - in your example, 4 arrays IN, a single string OUT.  Then write the string to file as a seperate operation.  GUI-displayed data can go through a similar transformation, the four arrays wired to a subVI which builds output-structures specifically for display.  It's a beginner's mistake to put lots of individual controls and indicators on the screen when groups of them are naturally related (in an object-oriented sense.)  Use clusters to group related controls - this will keep the diagram much cleaner.
    One more question: at what point (either # of data points or frequency of data collection) does it become necessary to use queues? Thanks.
    Well, there's not really a clearly definable "point".  I'd say if your update-rate climbs above 100Hz, or you witness poor program or system performance, then it's time.  The scenario you've described is a fairly simple acquire/display&log loop - and simple is good.   Then-again people can't see/react-to updates faster than about 10Hz - so it doesn't make sense to sacrifice performance - if performance becomes an issue.
    Re: queues:  Queues are sometimes used to buffer data that's "produced" in one place and "consumed" in another.
    Here, if/when logging data, you're logging with every DAQ.  I wouldn't recommend using a queue to transport data from a "DAQ loop" to a "Logging-loop" - those functions can be in the same loop.  Should/could a queue be used to get data from a "DAQ loop" to update the GUI at a lower frequency?  Sure, but a Notifier might be a better choice.   Further, in the (simple?) program you've described, you might use a case structure (True/False) to only update FP indicators every "X" iterations - a simple solution that doesn't require Queues or Notifiers.
    Cheers!
    "Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)

  • My iTunes won't open! It keeps saying 'The iTunes Library.itl is locked on a locked disk or you not have write permission for this file.' Please Help!

    My iTunes won't open! It keeps saying 'The iTunes Library.itl is locked on a locked disk or you not have write permission for this file.' Please Help!

    this may happen on external drives if:
    The external drive was hotpluged (removed) without going the correct "eject" way
    The iTunes library (database) got corrupted
    First Aid for external drive
    Close iTunes
    Unmount (eject) external drive the right way.
    Mount drive again
    Go to Workplace -> right click external drive -> choose "clean up" This will force the filesystem to rescan the file structure of the drive and rebuilding the file system table and journaling file.
    After the tool shows "done" (could last some time depending on size of drive) restart iTunes
    If your iTunes library is on your internal drive, this may happen
    The system was not shoot down correct, e.g. "pulled the plug"
    The iTunes library (database) got corrupted
    First Aid for internal hard drive
    Close iTunes
    Reboot system
    Go to Workplace -> right click external drive -> choose "clean up"
    After the tool shows "done" (could last some time depending on size of drive)
    Reboot system, restart iTunes
    If none of the above fixes your problem, post here.
    Lupunus

  • How to write to a log file within a JSP

    Hello everybody,
    do you know how to write to a log file within a JSP.
    my code is (/space/SP/tlf/ExcepcionJava.jsp):
    <html>
    <body bgColor=#C4E1FF>
    <%@ page import="java.io.*" %>
    <%
         FileWriter salida = new FileWriter(response.encodeURL("log.txt"));
         salida.write(request.getParameter("errorMsg"));
         salida.close();
    %>
    </body>
    </html>.. I run under Solaris, Jrun 2.3.3
    I have also test with getServletContext().getRealPath(), but I get /netsrv/nes/docs/ instead of /space/SP/tlf/

    Hi,
    Give the full path of the log file to the FileWriter. Such as;
    FileWriter salida = new FileWriter(response.encodeURL("/usr/local/tomcat/logs/testlogs/log.txt"));
    nurettin

  • Need example with write to DATA log file programmatically?

    Hi all,
    I would like to request for an example of writing a datalog (*.DAT) file which could do this.
    Datalog file.
    NAME: AGE: SEX: (header)
    john 16 M (data)
    marie 55 F
    Dolah 34 M
    The program can also let me to add in new data and then store in the same file.dat. The data (hopefully) can be written to the bottom of the last saved entry of data. (eg. after the row Dolah).
    I need to do this so that I can open and read back the datalog file and use the data for other purpose.
    Please help,
    juni

    You've got some examples in Fundamentals>File Input and Output but one of the easiest things to do is to modify Write Strings to Spreadsheet File.vi to write strings as detailed at the bottom of the diagram and then save it to a different place and with a different name.
    Attachments:
    Spreadsheet_File_Write.jpg ‏17 KB

  • Java.util.logging: write to one log file from many application (classes)

    I have a menuapp to launch many applications, all running in same JVM and i want to add logging information to them, using java.util.logging.
    Intention is to redirect the logginginfo to a specific file within the menuapp. Then i want all logging from all applications written in same file. Finally, if needed (but i don't think it is), i will include code to write logging to specific file per app (class). The latter is probably not neccessary because there are tools to analyse the logging-files and allow to select filters on specific classes only.
    The applications are in their own packages/jars and contain following logging-code:
            // Redirect error output
            try {
                myHandler = new FileHandler("myLogging.xml",1000000,2);
            } catch (IOException e) {
              System.out.println("Could not create file. Using the console handler");
            myLogger.addHandler(myHandler);
            myLogger.info("Our first logging message");
            myLogger.severe("Something terrible happened");
            ...When i launch the menuapplication, it writes info to "myLogging.xml.0"
    but when i launch an application, the app writes info to "myLogging.xml.0.1"
    I already tried to leave out the creation of a new Filehandler (try/catch block in code above) but it doesn't help.
    Is it possible to write loginfo to same specific file?

    You should open/close it somehow at every write from different processes.
    But I personally prefer different file names to your forced merging, though.

  • Configure log4j to write to different log files conditionally

    Hi folks,
    Is there is way log4j could be configured to write to multiple log files conditionally? Let me try to explain what i am trying to do.
    I have two classes DatabaseChecker and FTPChecker extends Checker class. Within Checker class, there is a method logTestResult(CheckerType c, boolean isFailed, int retry, int isMaxRetryExceeded). Depending on the CheckerType(database or FTP), I need to write log outputs to different files (dbchecker.log or ftpchecker.log). How do i configure log4j to do this?
    I've seen how to configure log4j based on classes from different package, but not sure on this one. Any clue would be much appreciated.

    lgmqy2000 wrote:
    I have two classes DatabaseChecker and FTPChecker extends Checker class. Within Checker class, there is a method logTestResult(CheckerType c, boolean isFailed, int retry, int isMaxRetryExceeded). Depending on the CheckerType(database or FTP), I need to write log outputs to different files (dbchecker.log or ftpchecker.log). How do i configure log4j to do this?
    if (checker.isType(CheckerType.DATABASE)) {
        dbLogger.info(someMessage);
    } else if (checker.isType(CheckerType.FTP)) {
        ftpLogger.info(someMessage);
    } else {
        defaultLogger.info(someMessage);
    }~

  • How to read the data file and write into the same file without a temp table

    Hi,
    I have a requirement as below:
    We are running lockbox process for several business, but for a few businesses we have requirement where in we receive a flat file in different format other than how the transmission format is defined.
    This is a 10.7 to 11.10 migration. In 10.7 the users are using a custom table into which they are first loading the raw data and writing a pl/sql validation on that and loading it into a new flat file and then running the lockbox process.
    But in 11.10 we want to restrict using temp table how can we achieve this.
    Can we read the file first and then do validations accordingly and then write to the same file and process the lockbox.
    Any inputs are highly appreciated.
    Thanks & Regards,
    Lakshmi Kalyan Vara Prasad.

    Hello Gurus,
    Let me tell you about my requirement clearly with an example.
    Problem:
    i am receiving a dat file from bank in below format
    105A371273020563007 07030415509174REF3178503 001367423860020015E129045
    in this detail 1 record starting from 38th character to next 15 characters is merchant reference number
    REF3178503 --- REF denotes it as Sales Order
    ACC denotes it as Customer No
    INV denotes it as Transaction Number
    based on this 15 characters......my validation comes.
    If i see REF i need to pick that complete record and then fill that record with the SO details as per my system and then submit the file for lockbox processing.
    In 10.7 they created a temporary table into which they are loading the data using a control file....once the data is loaded into the temporary table then they are doing a validation and updating the record exactly as required and then creating one another file and then submitting the file for lockbox processing.
    Where as in 11.10 they want to bypass these temporary tables and writing it into a different file.
    Can this be handled by writing a pl/sql procedure ??
    My findings:
    May be i am wrong.......but i think .......if we first get the data into ar_payments_interface_all table and then do the validations and then complete the lockbox process may help.
    Any suggestions from Oracle GURUS is highly appreciated.
    Thanks & Regards,
    Lakshmi Kalyan Vara Prasad.

  • I've just opened iTunes on my Mac with an error "The iTunes Library.itl file is locked, on a locked disk, or you do not have write permission for this file.". I created a shirred library so that all users on my Mac can access the same library. Help?

    I have just opened ITunes on my Mac and the following error occurred "The iTunes Library.itl file is locked, on a locked disk, or you do not have write permission for this file.". When I setup my Mac I created a shared user area to contain my ITunes library so that I could share it with another user logged onto my Mac. However the error above gives me the impression that the library file is locked... I've checked and it does not seem to be locked under the "get info" fie information. Has anyone come across this before and found a solution?

    You also need to make sure you have both read and write permission for the file, or for the whole iTunes folder for that matter.  That's also done in Get Info for the file or folder concerned.
    Read the part about changing permissions on the iTunes folder in: https://discussions.apple.com/message/11583914

Maybe you are looking for

  • 500   Internal Server Error on opening Business Planning in SAP Portal 7.3

    Dear All, While trying to start working with Business Planning role in SAP Portal 7.3, I am getting the following error message. Please Help. Detailed Exception Detailed Exception Chain com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: Exc

  • Just upgraded to Firefox 4 Beta 11 and Sync no longer works

    tested on Windows XP SP3. After updating to Beta 11 Sync stopped working. Tried to reset account and now the Sync does nothing when I try and either Create a new account or Connect to existing account

  • I want to speed up acrobat 9 by control the plugins

    it's too slow to open files,especially had many plug_ins installed like pitstop. i think nobody like to pay about one minute to prepar openning a PDF for just viewing.and it use almost all the CPU resource in this time. as a little program deed, the

  • Sort Contacts by Company Workaround

    I keep all contacts on the iPhone and do not sync. I create a complete contact record for each person and sort and display them by last name. I then create a "contact" for each company, putting the company name in the Last Name field. I then "Add Fie

  • Mac OS 10.3.9 can't read new Fantom Drive external disc.

    I have a Fantom Drive with Firewire & USB 2.0 capabilities. I use it to back up my MacBook Pro (OS 10.5.8). My MacBook Pro reads the drive without any problem when I hook them up. My wife's MacBook (OS 10.5.2) also reads it. The problem I have is wit