setFilePointer

ChemAxon 587f88acea

21-09-2004 08:53:16

Hi,


I want to read in single molecules from a huge sdf file. I know where to put the FilePointer because I have stored the start position of this molecule with the Molecule.getStartPosition() method. But actually the MolInputStream.setFilePointer(long) method doesn't work (as is written in your API). But RandomAccessFile isn't compatible with MolImporter anymore, is it? I want to use the MolImporter.read() method at that special point in my file because it's very comfortable (Good Job!). How can I set the FilePointer and still use MolImporter.read()?





(Till now I use the skipToNext() method every time from the beginning of the file, but that's becoming too slow at the end of the file, of course.)





Thank you very much.

ChemAxon 7c2d26e5cf

21-09-2004 16:46:48

The following code demonstrates how you can load a molecule from a random access file:


Code:
 


        InputStream is = null;


        RgMolecule mol = new RgMolecule();


        MolImporter importer = null;


        try{


            File f = new File(filename);


            RandomAccessFile raf = new RandomAccessFile(f.getPath(),"r");


            is = new FileInputStream(raf.getFD());


            raf.seek(pos);


            importer = new MolImporter(is);


            importer.read(mol);


        } catch(Exception ex) {


            ex.printStackTrace();


        }


    }





Note: The "filename" and "pos" variables specify the name of the SD file and the position of the molecule in the file.

ChemAxon 587f88acea

22-09-2004 07:13:41

It works!


Thank you so much for your help.