Skip to content

Images & Other File IO

drewhannay edited this page Jun 16, 2012 · 1 revision

If you need to programmatically access an image from the "images" source directory, you can do so with the call:

getClass().getResource("/myImage.png");

or if you are in a static method:

MyClass.class.getResource("/menus/myOtherImage.png");

Note the / before the file name. Each resource path must begin with a /, but can also have subdirectories, as long as the subdirectories exist in the images folder.

File IO should use the FileUtility class. Methods exist for obtaining a File object that points to each of our directories (AI, Variants, Games in Progress, and Completed Games) and for obtaining a String array of any filenames which exist in each of those directories. This class should be used for all File IO because it takes care of several messy implementation details for you, such as making sure all the appropriate directories exist before writing to them and ensuring that all paths are correct.

Clone this wiki locally