Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

To load the File from the RAR file , Especially From Classpath

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Techies,

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)
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you wish to do after creating a File object? You have the other method in Class to get the resource as a InputStream - http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)

If you want to read the file contents, you can use the above method.
 
rosan samuel
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Jai wrote:What do you wish to do after creating a File object? You have the other method in Class to get the resource as a InputStream - http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)

If you want to read the file contents, you can use the above method.



I am using the File Object to do some validation. and then i will read it.


 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you do getResourceAsStream() and if the InputStream is not null, then you know you have the file is present for sure.

So no need to convert into File and do this check - File sName = new File("C:/ss.txt"); if (sName.exists()) {.

You can proceed with the next step of reading the InputStream.
 
Always! Wait. Never. Shut up. Look at this tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic