Class.getResourceAsStream(String name) has the following syntax.
public InputStream getResourceAsStream(String name)
In the following code shows how to use Class.getResourceAsStream(String name) method.
import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; /* w w w .j a v a2s .com*/ public class Main { public static void main(String[] args) throws Exception { String val = ""; InputStream i = Main.class.getResourceAsStream("text.txt"); BufferedReader r = new BufferedReader(new InputStreamReader(i)); // reads each line String l; while ((l = r.readLine()) != null) { val = val + l; } i.close(); } }