Re: 20050215:netCDF Java - NetcdfFile open method does not work as suggested

Unidata Support wrote:

------- Forwarded Message

To: support-netcdf-java@xxxxxxxxxxxxxxxx
From: "Alain Boucher" <boucher@xxxxxxxxxxxxxxxxxxxxxxx>
Subject: netCDF Java - NetcdfFile open method does not work as suggested
Organization: UCAR/Unidata
Keywords: 200502151901.j1FJ1u9O023527

Institution: Fisheries and Oceans Canada
Package Version: 2.2 (alpha)
Operating System: WindowsXP
Hardware Information: Intel P4
Inquiry: Hi there,

    I have downloaded the latest release of the Java NetCDF library.  I noticed 
that when using the open(String location) method on a NetcdfFile object, the 
method crashes when the file is empty (size of 0 bytes).

    I am not sure if the problem results from an ill-formed Netcdf structure or 
from the null size of the file, but the result is I get a OutOfMemoryError.

    However, the API suggests that it should throw an IOException() if the 
method fails.

    If I am misinterpreting what the method should do, does that mean I have to 
open a File object (from to first check if the file is a 0-length file?

    Thanks a lot in advance and congratulations on the great work you did of 
making that Java Netcdf library!  It is actually very helpful to our department!

NOTE: All email exchanges with Unidata User Support are recorded in the
Unidata inquiry tracking system and then made publicly available
through the web.  If you do not want to have your interactions made
available in this way, you must let us know in each email you send to us.

------- End of Forwarded Message
Hi Alan

When i run the NetcdfFile.main()

public static void main( String[] arg) throws Exception {

   try {
     String filename = "C:/data/bad/";
     NetcdfFile ncfile =;

     System.out.println( ncfile.toString());
   } catch (Exception e) {

I get: Cant read C:/data/bad/ not a valid NetCDF file.
   at ucar.nc2.NetcdfFile.main(

can you try that and send me your output? thanks