We use the predefined object System.in of the class InputStream.
InputStream is = System.in;
We create an object of the class FileInputStream (subclass ofInputStream) associated to the File object that identifies the file to open for reading.
FileInputStream is = new FileInputStream("data.txt");
We could also create a File object starting from the filename, and use such an object to create the FileInputStream:
File f = new File("data.txt"); FileInputStream is = new FileInputStream(f);
We create an object of the class URL (defined in the librery java.net) that identifies the Internet resource we want to open for reading, and we invoke the method openStream(), which returns the corresponding InputStream object.
URL u = new URL("http://www.inf.unibz.it/"); InputStream is = u.openStream();