3 Replies Latest reply: Jun 15, 2007 3:56 AM by 807605 RSS

    Reading a file from a jar

    807605
      The following code works on my Windows machine, but fails on my Linux box:
      String line;
              try {
                  BufferedReader br=new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/hss/app/images/mappings.txt")));
                  while ((line = br.readLine()) != null) {
                      if (line.indexOf('=') > -1) {
                          String[] s = line.split("[=]");
                          mappings.put(s[0].trim(), s[1].trim());
                      }
                  }
              } catch (IOException ex) {
                  ex.printStackTrace();
              }
      With the following error:
      Exception in thread "main" java.lang.ExceptionInInitializerError
              at hss.cris3.ImageManager.getInstance(ImageManager.java:43)
              at hss.cris3.Application.<init>(Application.java:87)
              at hss.app.cris.<init>(cris.java:78)
              at hss.app.cris.main(cris.java:1064)
      Caused by: java.lang.NullPointerException
              at java.io.Reader.<init>(Reader.java:61)
              at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
              at hss.cris3.ImageManager.<init>(ImageManager.java:26)
              at hss.cris3.ImageManager.<init>(ImageManager.java:19)
              at hss.cris3.ImageManager$ImageManagerHolder.<clinit>(ImageManager.java:39)
              ... 4 more
      Can anyone explain why? And perhaps more importantly what the solution is? Thanks.