Rajarsh and Sulev are right, you need a close in there to flush the buffers. 
Thus:


 public static void writeSDF() throws IOException, CDKException  {
    String filename = "/Users/lochana/Desktop/test.sdf";
    SDFWriter writer = new SDFWriter(new FileWriter(new File(filename)));
    for (IAtomContainer ac : compounds) {
      writer.write(ac);
    }
    writer.close();
    System.out.println("Done!");
  }

However, this isn't very good coding practice because it doesn't cover 
exception handling. Doing it properly is a bit tricky, but Java 7 now has a new 
syntax that does all this for you:

 public static void writeSDF() throws IOException, CDKException  {
    String filename = "/Users/lochana/Desktop/test.sdf";
    try (SDFWriter writer = new SDFWriter(new FileWriter(new File(filename)))) {
      for (IAtomContainer ac : compounds) {
        writer.write(ac);
      }
    }
    System.out.println("Done!");
  }

Unfortunately this doesn't actually work for SDKWriter because SDKWriter 
doesn't implement java.io.Closeable. So, a suggestion for change: all CDK 
writers and readers that have a close() method should have "implements 
Closeable" added to their class definition. That should be enough to allow this 
really useful idiom to be used.

Jonty


------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Cdk-user mailing list
Cdk-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cdk-user

Reply via email to