Fileoutputstream! How to use it?

Whe I use fileoutputstream what is the type of file that i should use to save a vector

Whe I use fileoutputstream what is the type of file
that i should use to save a vectorFileOutputStream fileOut = new FileOutputStream("yourFileName");
ObjectOutputStream objOut = new ObjectOutputStream( fileOut );
objOut.writeObject( yourVector );
for reading the vector back in:
FileInputStream inFile = new FileInputStream("yourFileName");
ObjectInputStream objIn = new ObjectInputStream( inFile );
Vector v = (Vector)objIn.readObject();
hth
partha

Similar Messages

  • How to use shell program parameters in java program??

    Hai all,
    I am writing a java program which must read strings from a file and must assign to variables.these strings are nothing but the output of ls -l command in shell. i need to have all those 9 fields in a file as variables.
    I cant find any method that will read only string.I came accross read line but that is not what i need.So, i thought of writing a shell script and by using awk, storing those 9 fields in 9 variables.. but how to use that variables in java programming???
    the shell script is executed by exec() but i need that variables also.
    Help me please:(
    thanks in advance

    i now changed the code... and closed the output file and then i read.Later i splited with the line i read.. but the same happened...
    this is the code:
    while ((l = inputStream.readLine()) != null)
                        op=new FileOutputStream("op.txt");//output of exec goes to this file
                        String[] cmd= {"/bin/sh","-c","ls -l "+l};
                        rt = Runtime.getRuntime();
                        proc = rt.exec(cmd);
                        // any error message?
                          StreamGobbler errorGobbler = new
                          StreamGobbler(proc.getErrorStream(), "ERR");
                        // any output?
                          StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "",op);
                        errorGobbler.start();
                               outputGobbler.start();
                        op.close();//the file is closed now
                        ip = new BufferedReader(new FileReader("op.txt"));     //now i opened to read
                        p=ip.readLine();
                        a=p.split("\\s");
                        ip.close();
                   }where i went wrong?

  • How to use XmlModify to sort the XML Data?

    Hello,
    I saw some examples explain how to use XmlModify in BDB XML package. I want to sort the XML data by several elements but my Java program could not work correctly.
    <CustomerData>
    <Transaction>
    <DLSFIELDS>
    <ADR_PST_CD>12345</ADR_PST_CD>
    <CLT_IRD_NBR>002</CLT_IRD_NBR>
    </DLSFIELDS>
    </Transaction>
    <Transaction>
    <DLSFIELDS>
    <ADR_PST_CD>12345</ADR_PST_CD>
    <CLT_IRD_NBR>102</CLT_IRD_NBR>
    </DLSFIELDS>
    </Transaction>
    // many nodes like transaction ...
    </CustomerData>
    My XQuery script was executed successfully in the shell. The script looks as follows:
    "for $i in collection('sample.dbxml')/CustomerData/Transaction order by xs:decimal($i//ADR_PST_CD), xs:decimal($i//CLT_IRD_NBR) return $i".
    The Java code :
    // create XmlManager
    XmlManager manager = // ...;
    // open XmlContainer
    XmlContainer container = // ...;
    XmlQueryContext context = manager.createQueryContext(XmlQueryContext.LiveValues, XmlQueryContext.Eager);
    XmlQueryExpression expression = manager.prepare("for $i in collection('sample.dbxml')/CustomerData/Transaction order by xs:decimal($i//ADR_PST_CD),xs:decimal($i//CLT_IRD_NBR) return $i", context);
    XmlModify modify = manager.createModify();
    XmlUpdateContext uc = manager.createUpdateContext();
    XmlDocument xmldoc = container.getDocument("sample.xml");
    XmlValue value = new XmlValue(xmldoc);
    long numMod = modify.execute(value, context, uc);
    System.out.println("Peformed " + numMod     + " modification operations");
    Could you point out the errors above or offer some suggestion?
    Thanks.

    I have other question of the sorting issue. Here are a large XML need to sort so I have to split it to multiple small XML files. After importing these files, I will use the XmlModify and XQuery to sort them. I'm not clear on the multiple XML files processing.
    1. Can the BDB XML ensure that all these XML files were sorted or how to update all documents with same logic.
    2. If I want export all these sorted documents, how can I ensure these files processed in sequence? Which document needs process first?
    The export method:
    public void export(String outputfile)throws Exception{
    final int BLOCK_SIZE = 5 * 1024 * 1024; // 5Mb
    try{
    File theFile = new File(outputfile);
    FileOutputStream fos = new FileOutputStream(theFile);
    byte[] buff= new byte[BLOCK_SIZE];                         
    XmlResults rs = container.getAllDocuments(new XmlDocumentConfig());               
    while(rs.hasNext()){
         XmlDocument xmlDoc = rs.next().asDocument();
         XmlInputStream inputStream = xmlDoc.getContentAsXmlInputStream();                    
         long read=0;
         while(true){
         read = inputStream.readBytes(buff, BLOCK_SIZE);
    fos.write(buff,0,(int)read);                    
         if(read < BLOCK_SIZE) break;
    inputStream.delete();
    xmlDoc.delete();
    rs.delete();
    //MUST CLOSE!
    fos.close();               
    catch(Exception e){
    System.err.println("Error exporting file from container " + container);
    System.err.println(" Message: " + e.getMessage());
    Thanks.

  • Want to learn how to use "serializable"

    Hello, everyone!
    I have never used "serializable" function of Java before. After reading API specification of java.sun.com and some tutorials of java.sun.com dealing with "serializable", I become more puzzled. I just want to know how to use the basic function of "serializable". Can anyone introduce me some basic tutorials or samples?
    Thanks in advance,
    George

    The function of serializable is to be able to serialize an object to a stream. Operations include writing an object to file, or to a network socket connection.
    That object can then be reconstructed from that file (or the reciever on the other end of a network socket can reconstruct the object.)
    Example
    MyClass object = new MyClass() //MyClass implements Serializable
    FileOutputStream fos = new FileOutputStream("C:\test.file"); //create a fileoutputstream to write to a file
    ObjectOutputStream out = new ObjectOutpuStream(fos); //an object outputstream to wrap the fileoutputstream
    out.writeObject(object); //write the object to the fileReading the object is like this
    FileInputStream fis = new FileInputStream("C:\test.file"); // create a fileinputstream to read from a file
    ObjectInputStream in = new ObjectInputStream(fis) // an ObjectinputStream to wrap the FileInputStream
    MyClass object = (MyClass)in.readObject();Exception catch blocks are not included but you do have to catch IOException for reading and writing, plus a few other exceptions for reading. Consult the API for details.

  • How to use the applet to upload the file ?

    I am facing a problem that , I don't know how to use applet to upload the file to server .
    I have the code to upload the file by using servlet .
    However , I want to use applet to upload the file .But , the format of servlet I have used is "multipart/form-data"
    but applet can not do so , I think it is the header of the data . I don't know what can I do .....
    Can anyone give me some suggestion or coding to write the file upload by using applet ?
    Besides , using the socket are there any other choices ?
    thx a lot !!!!

    Well, to upload files you need to
    Server App - running on the webserver
    1. Open a socket
    (Study the classes Socket, InputStream, OutputStream in the Java API)
    2. Wait for connection.
    3. Open FileOutputStream
    3. Read data from InputStream, Write to FileOutputStream
    4. Close InputStream and FileOutputStream
    Applet
    1. Open a filedialog (Swing, AWT)
    2. Open file (FileInputStream)
    3. Connect to uploadServer (steps described above)
    4. Read FileInputStream, write OutputStream
    5. Close File and Socket
    This is just simpl and basic terms get you on the right track
    Jonas

  • Sample project how to use Itext (pdf) in webdynpro

    Hi all,
    Have someone a sample how to use Itext in a webdynpro.
    Richard

    Hi Roberto and Bala,
    Sorry, I was thinking the wrong way!!
    Please can you check my source, I a'm get an error by opening the new window. the error : D:\PDFfromJava.pdf (The system cannot find the file specified)
    this my source:
        //@@begin wdDoInit()
        wdContext.currentPersonalDataElement().setFirstName("Richard");
        wdContext.currentPersonalDataElement().setLastName("Middelburg");
         Document document = new Document();
         try {
          PdfWriter.getInstance(document, new FileOutputStream("D:
    PDFfromJava.pdf"));
           document.open();
           document.add(new Paragraph("Hi, this is demo PDF file from JAVA!"));
         catch(DocumentException de) {
         //     wdComponentAPI.getMessageManager().reportException(de.getMessage(),false);
         wdContext.currentContextElement().setTest("fout1");
         }catch(IOException ioe) {
         //     wdComponentAPI.getMessageManager().reportException(ioe.getMessage(),false);
         wdContext.currentContextElement().setTest("fout2");
         File file = new File("D:
    PDFfromJava.pdf");// from iText library
         try
              IWDResource wr = WDResourceFactory.createCachedResource(getBytesFromFile(file), "PDF Report", WDWebResourceType.PDF);
              IWDWindow w = wdComponentAPI.getWindowManager().createNonModalExternalWindow(wr.getUrl(0), "PDF Report");
              w.show();
         catch (Exception e)
              wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage(), false);
              wdContext.currentContextElement().setTest("fout3");
        //@@end
    //@@begin others
      public static byte[] getBytesFromFile(File file) throws IOException {
                    InputStream is = new FileInputStream(file);
                    // Get the size of the file
                    long length = file.length();
                    // You cannot create an array using a long type.
                    // It needs to be an int type.
                    // Before converting to an int type, check
                    // to ensure that file is not larger than Integer.MAX_VALUE.
                    if (length > Integer.MAX_VALUE) {
                         // File is too large
                    // Create the byte array to hold the data
                    byte[] bytes = new byte[(int)length];
                    // Read in the bytes
                    int offset = 0;
                    int numRead = 0;
                    while (offset < bytes.length
                             && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
                         offset += numRead;
                    // Ensure all the bytes have been read in
                    if (offset < bytes.length) {
                         throw new IOException("Could not completely read file "+file.getName());
                    // Close the input stream and return bytes
                    is.close();
                    return bytes;
      //@@end
    Richard

  • How to use the javadbf in cfmx 7?

    I have downoad the javadbf.jar from the
    http://sarovar.org/projects/javadbf/,but
    i don't know how to use it in cfmx 7,can you help me?
    Thanks.

    Hi,cf_dev2 ,I have an other problem with javadbf.
    Now i can read dbf file with javadbf,But i can not write dbf
    file, i don know Java code below.
    import com.linuxense.javadbf.*;
    import java.io.*;
    public class DBFWriterTest {
    public static void main( String args[])
    throws DBFException, IOException {
    // let us create field definitions first
    // we will go for 3 fields
    DBFField fields[] = new DBFField[ 3];
    fields[0] = new DBFField();
    fields[0].setName( "emp_code");
    fields[0].setDataType( DBFField.FIELD_TYPE_C);
    fields[0].setFieldLength( 10);
    fields[1] = new DBFField();
    fields[1].setField( "emp_name");
    fields[1].setDataType( DBFField.FIELD_TYPE_C);
    fields[1].setFieldLength( 20);
    fields[2] = new DBFField();
    fields[2].setField( "salary");
    fields[2].setDataType( DBFField.FIELD_TYPE_N);
    fields[2].setFieldLength( 12);
    fields[2].setDecimalCount( 2);
    DBFWriter writer = new DBFWriter();
    writer.setFields( fields);
    // now populate DBFWriter
    Object rowData[] = new Object[3];
    rowData[0] = "1000";
    rowData[1] = "John";
    rowData[2] = new Double( 5000.00);
    writer.addRecord( rowData);
    rowData = new Object[3];
    rowData[0] = "1001";
    rowData[1] = "Lalit";
    rowData[2] = new Double( 3400.00);
    writer.addRecord( rowData);
    rowData = new Object[3];
    rowData[0] = "1002";
    rowData[1] = "Rohit";
    rowData[2] = new Double( 7350.00);
    writer.addRecord( rowData);
    FileOutputStream fos = new FileOutputStream( args[0]);
    writer.write( fos);
    fos.close();
    and this:
    DBFWriter writer = new DBFWriter( new File(
    "/path/to/a/new/file")); /* this DBFWriter object is now in Syc
    Mode */
    Can you write it use CFML,thank you.

  • How to use XMLEncoder to save Complicated XML??

    I think I posted in an improper forum: java programming, so repost here. Please excuse me.
    Dear friends, good weekend and happy thanksgivings.
    I met a problem when I use XMLEncoder to generate a complicated XML like following:
    <?xml version="1.0"?>
    <messages>
      <note ID="501">
        <to>Tove</to>
         <DeliveryAddress>
              <Street>12345</Street>
              <City>Parsinpany</City>
              <County>ABC</County>
              <State>NJ</State>
              <Country>USA</Country>
             </DeliveryAddress>
         <ContactID>
              <CompanyID>
                   <Address>12345</Address>
                   <City>Alnomre</City>
                   <County>BBB</County>
                   <State>TX</State>
                   <Country>USA</Country>
                  </CompanyID>
              <phone>1800-1234567</phone>
              <fax>123-456-7890</fax>
             </ContactID>
        <from>Jani</from>
        <heading>Reminder</heading>
        <body>Don't forget me this weekend!</body>
      </note>
      <note ID="502">
        <to>Jani</to>
        <from>Tove</from>
        <heading>Re: Reminder</heading>
        <body>I will not!</body>
      </note>
    </messages>How to use XMLEncoder to generate abobe XML or one that has namespaces in it??
    I can use simple
    XMLEncoder o = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(filename)));
                                  o.writeObject(mm.getBounds());     //get all position;
    but cannot generate above complicated XML.
    What is the right way to do it??
    any good example??
    Thanks

    My question is also how to use XMLEncoder to create attributes and and namespace, add child nodes to its parent, or remove nodes from their parent etc
    Thanks

  • How to use FileDescriptor?

    hai
    if anybody know how to use the FileDescriptor?
    pls infrom me. this is use to append a line in an existing file
    this is very urgent pls reply soon
    shafeek

    FileOutputStream fos = new FileOutputStream("file.txt", true);This tells it to append... see the API for more info

  • How to use one email adress for multiple recipients

    Hello,
    I'd like to know how to use one email adress for multiple recipients. 
    this would be very useful or projects. for example;
    if i send one mail to [email protected], all people in this project get an email.
    I will add the people in this project myself. 
    I know it is possible, but I don't know how to do it ;-)
    please help me! 

    Hope this help.
    _http://technet.microsoft.com/en-us/library/cc164331(v=exchg.65) .aspx

  • Can't figure out how to use home sharing

    Since the latest couple iTunes updates, my family and I can not figure out how to use home sharing. Everyone in our household has their own iTunes, and for a long time we would just share our music through home sharing. But with the updates, so much has changed that we can no longer figure out how to use it.
    I have a lot of purchased albums on another laptop in the house, that im trying to move it all over to my own iTunes, and I have spent a long time searching the internet, and everything. And I just can't figure out how to do it. So.... how does it work now? I would really like to get these albums from my moms iTunes, onto mine. I would hate to have to buy them all over again.
    If anyone is able to help me out here, that would be great! Thanks!

    The problem im having is that after I am in another library through home sharing, I can't figure out how to select an album and import it to my library. They used to have it set up so that you just highlight all of the songs you want, and then all you had to do was click import. Now I don't even see an import button, or anything else like it. So im lost... I don't know if it's something im doing wrong, or if our home sharing system just isn't working properly.
    Thanks for the help.

  • How to use the same POWL query for multiple users

    Hello,
    I have defined a POWL query which executes properly. But if I map the same POWL query to 2 portal users and the 2 portal users try to access the same page simultaneously then it gives an error message to one of the users that
    "Query 'ABC' is already open in another session."
    where 'ABC' is the query name.
    Can you please tell me how to use the same POWL query for multiple users ?
    A fast reply would be highly appreciated.
    Thanks and Regards,
    Sandhya

    Batch processing usually involves using actions you have recorded.  In Action you can insert Path that can be used during processing documents.  Path have some size so you may want to only process document that have the same size.  Look in the Actions Palette fly-out menu for insert path.  It inserts|records the current document work path into the action being worked on and when the action is played it inserts the path into the document as the current work path..

  • How to use airport time capsule with multiple computers?

    I'm sure there are some thread about this but i couldn't find it... so sorry for that but hear me out! =)
    I bought the AirPort Time Capsule to back up my MBP
    And so i did.
    then i thought "let give this one a fresh start" so i erased all of it with the disk utility and re-installed the MBP from the recovery disk.
    I dont want all of the stuff i backed up just a few files and some pictures so i brought that back.. so far so good.
    Now i want to do a new back up of my MBP so i open time machine settings, pick the drive on the time capsule and then "Choose" i wait for the beck up to begin, and then it fails.  It says (sorry for my bad english, im swedish haha) "the mount /Volume/Data-1/StiflersMBP.sparsebundle is already in use for back up.
    this is what i want:
    i want the "StiflersMBP.sparsebundle" to just be so i can get some stuf when i need them. it's never to be erased.
    i want to make a new back up of my MBP as if it's a second computer...
    so guys and girls, what is the easiest and best solution?
    Best regards!

    TM does not work like that.
    If you want files to use later.. do not use TM.
    Or do not use TM to the same location. Plug a USB drive into the computer and use that as the target for the permanent backup.
    Read some details of how TM works so you understand what it will do.
    http://pondini.org/TM/Works.html
    Use a clone or different software for a permanent backup.
    http://pondini.org/TM/Clones.html
    How to use TC
    http://pondini.org/TM/Time_Capsule.html
    This is helpful.. particularly Q3.
    Why you don't want to use TM.
    Q20 here. http://pondini.org/TM/FAQ.html

  • How to use multiple ipods on one account

    I have an Ipod classic and just bought my sons two nano's how do I use these on the same account without changing my account info?

    Take a look here:
    How to use multiple iPods with one computer
    Forum Tip: Since you're new here, you've probably not discovered the Search feature available on every Discussions page, but next time, it might save you time (and everyone else from having to answer the same question multiple times) if you search a couple of ways for a topic, both in the relevant forums, in the User Tips Library and in the Apple Knowledge Base before you post a question.
    Regards.

  • How to use a Table View in AppleScriptObjC

    How can I use a table view and add data to it? And how can I display a button cell and image cell in the table? Thanks.

    Hi all,
    Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?
    for ex : select * from (tab_name) where....?
    Can we do inner join on such select statements? If so how?
    Thanks & Regards,
    Mallik.

  • How to use '|' delimited as seprator in GUI_DOWNLOAD ? Plz suggest me ,,

    how to use '|' delimited as seprator in GUI_DOWNLOAD ? Plz suggest me ,,
    i want the output should be seprated by '|' delimited when i download the file.

    Hi,
    We will pass the seperator to the WRITE_FIELD_SEPARATOR parameter as
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    filename = v_file
    write_field_separator = '|'
    TABLES
    data_tab = itab[] . "Our internal talbe filled with data
    Re: Why Function GUI_DOWNLOAD can create XML file but not a flat file?
    Award points if useful
    Thanks,
    Ravee...

Maybe you are looking for