Question

I try to load the File from RAR . I am using the

sFileName=Thread.currentThread().getContextClassLoader().getResource("common.xml").getFile();

Immediately, my requirement is load the file in to File IO.

fSettings = new File(sFileName);
if (fSettings.exists() && fSettings.isFile()) {

Is it possible to load the File from classpath and Create File object? Would it be possible to validate?

Share your thoughts.

I get this following error:

22:44:16,718 ERROR [STDERR] java.io.FileNotFoundException: file:\C:\Servers\ApplicationServers\jboss-4.2.3.GA\server\XXXX\tmp\deploy\XXX.ear-contents\XXX.rar!\common.xml (The filename, directory name, or volume label syntax is incorrect) 22:44:16,718 ERROR [STDERR] at java.io.FileInputStream.open(Native Method)

Was it helpful?

Solution

The URL that you get with the getResource() might not be a file, and in this case it's not because your common.xml is inside of a RAR file. If you want to access common.xml, just do a getResourceAsStream() and read the InputStream.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top