How to multiple objects stored in a file.

Hi,
there is a file on which multiple object have been written.
Now while reading it back, is it necessary to read the objects in the same sequence in which they were written or i can randomly read any object?
thanx
deepak saini

If that's really a concern, you could write the objects to separate files.
Alternatively, if you're really keen, look at RandomAccessFile. You'd have to build InputStream and OutputStream bridges to be able to use ObjectInputStream and ObjectOutputStream. You'd probably want to use BufferedInputStream and BufferedOutputStream in there too.
You'd start by writing a long of value zero the file. Then use a new ObjectOuptutStream for each object (rembering to close each one), retaining a List of offsets into the file where the objects start. Then you'd write the List itself using another ObjectOutputStream. Finally you position back to the beginning of the file, and write the offset of the List as a long, overwriting the long zero value.
The reading side is left for as exercise for the reader.
This would allow you to read directly any object given its index into the List.
This is only worthwhile if you're talking about lots of objects.
And, as I said, only if you're keen :)
Sylvia.

Similar Messages

  • How to read multiple objects stored in a file.

    Hi,
    there is a file on which multiple object have been written.
    Now while reading it back, is it necessary to read the objects in the same sequence in which they were written or i can randomly read any object?
    thanx
    deepak saini

    I suppose you could use random file access, but you would need to keep track of where you put the objects.

  • Need help (desperately) '^_^ in writing multiple objects in a single file

    For all those Java guru out there please help me,
    I want to write a simple application that can serialize objects in a single file. Currently I know how to serialize one object in one file using the ObjectOutputStream's writeObject () method.But the problem is that if i have 10.000 objects to serialize then I will have 10.000 file in my HD. To simplify things I want to write those 10.000 objects in a single file. But I dont know how to do that, any one can help ??

    You can write any number of objects of any type into a file when you serialize them. You need to realize that once they're written to the file, they're all placed in there as type Object, so there really isn't any distinction between any of them. You don't have a file that contains only Shapes, or only Images. You write them out as Objects, and then you discover their types later as your deserialize them and read them in. You should read into the "Reflection" capabilities that all objects have. You write an Image to a file, and then a Shape, and then a Color, you can later pack these all into an ArrayList as you read them in, and when you use them discover their type using reflection.
    -Jason Thomas.

  • How can multiple users spool to same file?

    I am using SQL*plus for 10g db. I am spooling query output to a file. Query should be run and spooled multiple times overwriting previous output.
    here is the main piece from the query.sql file
    SPOOL output.txt
    SELECT....
    SPOOL OFF
    Let's say user Dan runs this query for the first time. An output.txt is created. Dan can run the query multiple times and each time new data is spooled to output.txt. Now Mike is trying to run this query. Nothing happens!
    I thought the issue has to be with file permissions. However, the issue remained after I gave ALL permissions (a=rwx) to both files: query.sql & output.txt. Funny thing is that I created query.sql and now I (or any other users, except Dan) cannot run it.
    Thank you!

    What's the umask of your system?
    umask
    %umask
    22
    %sqlplus / as sysdba
    SQL*Plus: Release 10.2.0.3.0 - Production on Mon Nov 10 12:11:03 2008
    Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SYS@adev>@test.sql
    SYSDATE
    10-NOV-08
    %ls -l test.txt
    -rw-r--r--   1 oracle     oinstall       455 Nov 10 12:11 test.txt
    ------------ Remove the old test.txt ----------------
    %umask 000
    %sqlplus / as sysdba
    SQL*Plus: Release 10.2.0.3.0 - Production on Mon Nov 10 12:17:16 2008
    Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SYS@adev>!umask
    0
    SYS@adxdev>@test.sql
    SYSDATE
    10-NOV-08
    %ls -l test.txt
    -rw-rw-rw-   1 oracle     oinstall       455 Nov 10 12:17 test.txt

  • How to read properties stored in jar file

    Hello
    I got one question.
    I created properties file in my project, which contains some texts for panels. When I start application from JBuilder all works fine. This priperies file is stored in path "cmt/locales/CMTModule.properties".
    Problem is only in case I created jar file in which is this mentioned properties file. When I run through doubleclick my file ins't loaded.
    My procedure for load resource is follow:
    ResourceBundle res = null;
    private void initLocales() {
            String packageName;
            String className;
            String bundleName = null;
            String name = null;
            int index;
            try {
                packageName = this.getClass().getPackage().getName().toLowerCase();
                className = this.getClass().getName().toLowerCase();
                index = className.lastIndexOf(".");
                if (index > -1) {
                    className = className.substring(index + 1);
                bundleName = packageName;
                bundleName = bundleName + ".locales.";
                bundleName = bundleName + className;
    res = ResourceBundle.getBundle(bundleName);
                res = new PropertyResourceBundle(this.getClass().getResourceAsStream("locales/"+ className  + ".properties"));
            } catch (Exception exception) {
                System.out.println("Error to get local settings");          
            try {
                locales = new Locales(res);
            } catch (Exception exception) {
                exception.printStackTrace();
        }Whats wrong ?

    Thank You Very Much
    Problem was in case insensivite, because I'm convert class name to lower case. I only removed function toLowerCase().
    I replace these lines
    packageName = this.getClass().getPackage().getName().toLowerCase();
          className = this.getClass().getName().toLowerCase();with
    packageName = this.getClass().getPackage().getName();
          className = this.getClass().getName();Thanks

  • How to save object to a local file.

    Hello all.
    I need to save an object, i.e. an ABAP program, to a local file and then be able to "import" it into another system.
    I am not talking about the lines of codes that can be saved as a local file, but the whole program including screens and so on. Something similar to releasing a transport with object R3TR PROG ZMYPROGRAM to another system, but instead to the local desktop.
    Anyone would know if this can be done?
    Regards
    Lande

    Hi,
    Vist the Link for complete Download there are some utility programs.
    http://www.dalestech.com
    Regards
    vijay

  • How to close the object after generation Excel file

    I have generated excel file. I save that file using "Save" button on dialog-box. After i go to menu navigation at that time i got javascript error.
    please give me the solution how to close objects after generating excel file.

    Hi,
    Pls don't forget to reward points and close the question if you find the answers useful.
    Eddy

  • How to print the image data stored in object of 'java.io.File' Class in jsp

    I have created a file object for the image file in the system temporary directory.Now I want to display it in my page. please tell,How to print the image data stored in object(in my program it is imgr) of 'java.io.File' Class in jsp

    Create a servlet which gets an InputStream of the file and writes it to the OutputStream of the response and call this servlet in `src` attribute. That's basically all.
    Here's an example which covers the most of the minimum needs: [http://balusc.blogspot.com/2007/04/imageservlet.html].

  • How can i execute multiple database operations using multiple objects

    i have data in files which i need to read/parse and insert/update the database. can someone tell me how can i read multiple statements at a time and process using multiple objects.

    This doesn't seem like too much of a JDBC question or at least the answer as I see it isn't unique or specific to JDBC.
    If you want to run multiple processes within your single program then you need to use Java threads. I would recommend you read up on how to properly code Java threads and if you have questions unique to your multi-threaded JDBC implementation come back and ask those questions.
    You may also want tot take advantage of a transaction manager that includes a database connection pool that will handle most of the complexity for you. Depending on the flexibility of your architecture you may not have to do any thread coding at all when using a transaction manager.

  • XML decoder on multiple objects in one file

    I am reading multiple (unknown amount) of objects from an XML file. This is my (working) code:
    FileInputStream fileIn = null;
              try {
                   fileIn = new FileInputStream(fileName);
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
              XMLDecoder decoder = new XMLDecoder(fileIn);
              boolean stop = false;
              ArrayList<Object> list = new ArrayList<Object>();
              while(!stop){
                   try{
                        list.add(decoder.readObject());
                   }catch(ArrayIndexOutOfBoundsException e){
                        stop = true;
              return list;Is there any way to do this more elegantly (without generating the exception first)? How can I know how many objects to read from the file?

    Hi!, Philm_12: Welcome, to Forum !. This Forum, is exclusive, for HP devices.

  • Can we resize/shrink data file if objects stored on fragmented space

    Can we shrink data file if objects stored on fragmented space
    for example if i
    1- delete records from a table
    2- shrink objects
    if i do above two process and then i can resize or shrink the datafiles on which these objects are stored.
    regards,

    AMIABU wrote:
    i have no any SQL that can show me fregmentation. can you please provide.
    regards,Then how do you know you have it and need to fix it?

  • How do I use Finder to modify file details in multiple files

    I am new to the mac (OS10.7.4) having recently transitioned from Windows (and go way back to CPM - for those that remember).  I am trying to achieve through finder what I can do in windows explorer by selecting multiple files, selecting  properties and then selecting (and then modifying) details.  I tried the similar thing on Finder using Get Info instead of Properties but only ended up with multiple windows, one for each file selected (and had to close each one individually! ).  Tried 'option-command-I' on multiple selected files, it worked, but the common tags that I wanted to alter where not available for editing.  I can simply, but clumsily, achieve the outcome I want by cutting and pasting the files to a usb stick, making the modifications on the windows machine and pasting them back on the mac.     This should be a simple basic operating system function regardless of platform - advice on how to find/achieve it appreciated!

    I find it best to use small little apps to help modify many files. Just serach for what you want to change and more often then not, you find software that does what you need, often free too.
    For Music tags: check out the free program "TriTag" to do what you want:
    http://www.feedface.com/projects/tritag.html
    For Music conversion (say, from FLAC to Apple Lossless) or MP3 to whatever... Use "XLD" (free)
    http://download.cnet.com/X-Lossless-Decoder/3000-2140_4-189505.html
    Bonus: VLC (free download) - has the ability to convert wma audio files, which is amazing, it's rare to find mac software that will convert wma to mp3 - http://9thport.net/2010/07/28/using-os-x-to-convert-wma-to-mp3-for-free/
    For file renaming in batch, I use "Name Mangler" - 10 bucks, app store.
    It has a lot of pro features and is very useful.
    good luck.
    - James

  • How do multiple users share files?

    How do multiple users on one computer share files in finder?

    Each user has a Public folder in his or her home folder. The files in that folder are readable by other local users.

  • How can I share a *.java source file across multiple projects in NetBeans?

    I'm sure this simple and a pretty common operation but how can I share a *.java source file across multiple projects in NetBeans? Right now I keep cut, coping and pasting the same source file between multiple projects to re-use the same code. But I could I make this source file a library file or something like that so that I could access it from any project. I assume this would be a generic operation but I mentioned NetBeans for clarity. Thanks.

    fiebigc wrote:
    I know I mentioned NetBeans but I'm most interested in the generic method for creating a library of source files that I can call into whatever program I am developing. I've done such a thing in C using header files and such but I'm trying to get a direction on how this is accomplished in Java. I'm sorry if I could edit the title I would. If anyone wants to be specific about NetBeans I welcome that too.
    Edited by: fiebigc on Jun 20, 2008 5:57 PM
    >I know I mentioned NetBeans but I'm most interested in the generic method for creating a library of source files that I can call into whatever program I am developing. I've done such a thing in C using header files and such but I'm trying to get a direction on how this is accomplished in Java. I'm sorry if I could edit the title I would. If anyone wants to be specific about NetBeans I welcome that too.
    Edited by: fiebigc on Jun 20, 2008 5:57 PM
    Create a class library.
    Write your code, compile it to .class files, put those class files in a .jar file and include the jar file in the classpath whenever you want to compile a project against it.

  • How do i scan multiple pages into one pdf file

    How do I scan multiple pages into one pdf file?

    That depends on your scanning software. Adobe Reader doesn't scan.

Maybe you are looking for

  • Can I have a list of all the top HD games on Symbi...

    Just tell the names of some good action games which can be played on Belle devices!!

  • CS5 crash when importing from external library

    Hello. I am using Flash CS5 on Win7 64 bit. I have made a flash site. On this site I am trying to add a photo gallery. I bought a flash XML photogallery from Active Den. The gallery is working fine but to get this into my site I need to import the li

  • Flash "Spinny" loader corrupted in FF in Windows with Flash player 10

    Everywhere else I have this on our site, it works fine. Here is where it is broken In a firefox browser (2, 3, 3.5) with flash player 10 in windows xp (flash player 9 looks fine) Everywhere else it looks fine.  I have attached the swf file & a screen

  • HT3986 boot camp has no option to put iso to external drive

    I have no blank discs and want to put windows iso on my thumbdrive. When I get to the spot in boot camp assistant where I check that option, it is blank. See my picture example at the url. So how do I put the iso on the thumbdrive and install it to m

  • Help::about sapXI ID AND IR

    thanks somebody's  method  .BUT the question about us sap xi id and ir has yet to be resolved. Now ,the xi id and ir still very slow to start. I am using a minicomputer server to start the sap xi id and ir,so about memery and cpu  that somebody sugge