Java examples for File Path IO:BufferedReader
get Resource Reader
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; public class Main { public static void main(String[] argv) throws IOException { Object caller = "java2s.com"; String resourceName = "java2s.com"; System.out.println(getResourceReader(caller, resourceName)); }// ww w. ja v a 2 s . co m public static Reader getResourceReader(final Object caller, final String resourceName) throws IOException { BufferedReader in = null; if (caller == null) { throw new IllegalArgumentException("caller is null"); } try { final InputStream stream = caller.getClass().getClassLoader().getResourceAsStream(resourceName); if (stream == null) { throw new java.lang.IllegalArgumentException("irresolvable resource " + resourceName); } in = new BufferedReader(new InputStreamReader(stream, "8859_1")); } catch (final java.io.IOException i) { throw new java.io.IOException("Failed to load resource: '" + resourceName + "'\n" + i.getMessage()); } return in; } }