/* The following method may be included in the class which needs it. * You may need to add import statements or make other adjustments. */ /** * Create a buffered Reader from a resource name. * A "resource" is a file (such as an image or a text file) needed by * a program. The resource name must be qualified * for the package it (and this class) are in. For example, if the package is * horoscope.model, a legal resource name is "horoscope/model/data.txt" * or "horoscope/model/this.txt". ILLEGAL names are "data.txt", "./data.txt", * "horoscope/this.txt" or "horoscope/view/data.txt". * * @param resourceName The resource name in the required format. * @return a BufferedReader for the resource. * @throws IOException Thrown if a problem loading. */ static BufferedReader readerFromResource(String resourceName) throws IOException { ClassLoader cl; URL url; BufferedReader newReader; //Find the class loader. This should be done using the //.class member of a class in the module. cl=HoroscopeModel.class.getClassLoader(); //Find the URL for the file. url = cl.getResource(resourceName); //Open the resource URL InputStream istream = url.openStream(); newReader = new BufferedReader(new InputStreamReader(istream)); return newReader; }