-2

When I compile this code in eclipse ,it throws a NullPointerException,but the code in the book is written in this way.Here is this code.

 InputStream in = ClassLoader
            .getSystemResourceAsStream("javagames/filesandres/Test1.txt");
 try {
            InputStreamReader reader =new InputStreamReader(in);
            BufferedReader buf = new BufferedReader(reader);
            String line = null;
            while ((line = buf.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (Exception e) {
            }
        }
    }
project_01
  • 31
  • 4

1 Answers1

-1

It's because you probably don't have a "javagames/filesandres/Test1.txt" therefore, the InputStream will be null.

Michael Markidis
  • 4,163
  • 1
  • 14
  • 21