[messages] [Module Design] Re: How to access files stored in a module?

uckelman uckelman at nomic.net
Mon Nov 22 15:38:04 MST 2010


"L.Tankersley" wrote:
> Look at VASSAL.tools.DataArchive; it is a wrapper for accessing
> members within a zip archive (in this case, a module file).  There are
> convenience routines for accessing images in the images/ directory
> (which is how I eventually found it), but you can also do things like:


Note that you really, really should have a finally block which properly
closes the stream here:


Code:

final	String myFile = "foo";
InputStream is = null;
try {
  is =
GameModule.getGameModule().getDataArchive().getInputStream(myFile);

  DataInputStream in = null;
  try {
    in = new DataInputStream(new BufferedInputStream(is));
    // do stuff with in
    in.close();
  }
  finally {
    IOUtils.closeQuietly(in);
  }
}
catch (FileNotFoundException e) {
  // handle the exception
}
catch (IOException e) {
  // handle the exception
}
finally {
  IOUtils.closeQuietly(is);
}




_______________________________________________
Read this topic online here:
http://www.vassalengine.org/forum/viewtopic.php?p=20634#p20634


More information about the messages mailing list