getresource

Copy directory from a jar file

不问归期 提交于 2019-11-26 09:46:54
问题 I have recently developed an application and created the jar file. One of my classes creates an output directory, populating it with files from its resource. My code is something like this: // Copy files from dir \"template\" in this class resource to output. private void createOutput(File output) throws IOException { File template = new File(FileHelper.URL2Path(getClass().getResource(\"template\"))); FileHelper.copyDirectory(template, output); } Unfortunately this doesn\'t work. I tried the

How to use ClassLoader.getResources() correctly? [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-11-26 06:28:45
问题 This question already has answers here : How to list the files inside a JAR file? (15 answers) Closed 3 years ago . How can I use ClassLoader.getResources() to find recursivly resources from my classpath? E.g. finding all resources in the META-INF \"directory\": Imagine something like getClass().getClassLoader().getResources(\"META-INF\") Unfortunately, this does only retrieve an URL to exactly this \"directory\". all resources named bla.xml (recursivly) getClass().getClassLoader()

Class.getResource() returns null

。_饼干妹妹 提交于 2019-11-26 05:56:45
问题 I am trying to display pictures on the JPanel but I keep getting the error : java.lang.IllegalArgumentException: input == null! I don\'t understand what is happening. Here is the code I am using: public void actionPerformed(ActionEvent e) { try { Image image=ImageIO.read(getClass().getResource(\"img/\" +num.getText()+\".jpg\")); Image resized = image.getScaledInstance(200, 200, 100); pictureFrame.setIcon(new ImageIcon(resized)); } catch (Exception ex){ ex.printStackTrace(); } } This just

How to list the files inside a JAR file?

给你一囗甜甜゛ 提交于 2019-11-25 22:57:58
问题 I have this code which reads all the files from a directory. File textFolder = new File(\"text_directory\"); File [] texFiles = textFolder.listFiles( new FileFilter() { public boolean accept( File file ) { return file.getName().endsWith(\".txt\"); } }); It works great. It fills the array with all the files that end with \".txt\" from directory \"text_directory\". How can I read the contents of a directory in a similar fashion within a JAR file? So what I really want to do is, to list all the

What is the difference between Class.getResource() and ClassLoader.getResource()?

孤街浪徒 提交于 2019-11-25 22:34:12
问题 I wonder what the difference is between Class.getResource() and ClassLoader.getResource() ? edit: I especially want to know if any caching is involved on file/directory level. As in \"are directory listings cached in the Class version?\" AFAIK the following should essentially do the same, but they are not: getClass().getResource() getClass().getClassLoader().getResource() I discovered this when fiddling with some report generation code that creates a new file in WEB-INF/classes/ from an