URL url = getClass().getResource("/myWonderfulResource.txt"); if (url == null) { throw new IllegalStateException("File not found: /myWonderfulResource.txt"); }