Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

RE: access to the file recursively in the jar file?

Thread view: 
pvii007 - 10 Dec 2005 08:38 GMT
If I have a file structure
/core/ (here is application)
/core/doc ( here is the doc )
/core/doc/filecollection1/
/core/doc/filecollection1/subcollection1/
/core/doc/filecollection1/subcollection2/
/core/doc/filecollection2/
/core/doc/filecollection2/subcollection1/
/core/doc/filecollection2/subcollection2/

I compress the application and doc in the jar file.
I want to access to every dir or file recursively.

How to write my code?

PS:
I have written the code
...

   File codebase = new File("/core/doc");
...
   public String read_file_recursive( File file)
   {
       String ret;
       if( codebase.isDirectory())
       {
           File[] filelist = codebase.listFiles();
           for( int i = 0 ; i < filelist;i++ )
           {
               ret += read_file_recursive(filelist[i]);
           }
       }
       else
       {
           // read file content ...
       }
       return ret;
   }
...
But it doesn't work in the jar file.

I guess that the problem occur at the concept of package or directory in the
jar file.
Andrew Thompson - 10 Dec 2005 10:19 GMT
> I compress the application and doc in the jar file.
> I want to access to every dir or file recursively.
...
> But it doesn't work in the jar file.
>
> I guess that the problem occur at the concept of package or directory in the
> jar file.

Yep.  The usual solution is to extract the internal jar's
to disk before first use.

Signature

Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew

Tris Orendorff - 11 Dec 2005 16:41 GMT
> If I have a file structure
> /core/ (here is application)
[quoted text clipped - 39 lines]
> I guess that the problem occur at the concept of package or directory
> in the jar file.

Get rid of the variable "codebase" and use the parameter "file" in its
place and it will work on a file system.  Start the whole thing with
"read_file_recursive(new File("/core/doc"));"

Signature

Sincerely,

Tris Orendorff
[Two antennae meet on a roof, fall in love and get married. The ceremony
wasn't much, but the reception was excellent.]

pvii007 - 13 Dec 2005 00:44 GMT
But if this class is compressed in the  jar file,the access to the file
recursivly by invoking read_file_recursivef(new File("/core/doc")) may not
be valid .

These files are not stored in the same package.I think the recursion
implementation of read_file method in the jar file will be more efficiency.
But it can't work.

"Tris Orendorff" <triso@remove-me.cogeco.ca> дÈëÏûÏ¢ÐÂÎÅ:Xns972976E29B3E1RepublicPicturesLtd@216.221.81.119...

>> If I have a file structure
>> /core/ (here is application)
[quoted text clipped - 43 lines]
> place and it will work on a file system.  Start the whole thing with
> "read_file_recursive(new File("/core/doc"));"
Thomas Weidenfeller - 13 Dec 2005 08:40 GMT
> But if this class is compressed in the  jar file,the access to the file
> recursivly by invoking read_file_recursivef(new File("/core/doc")) may not
[quoted text clipped - 3 lines]
> implementation of read_file method in the jar file will be more efficiency.
> But it can't work.

Why on earth do you insist on mixing File() objects with access to jar
file contents? A jar in a jar is not a File()! Like any other item in a
jar it is a JarEntry (a subclass of ZipEntry) which you can access as a
stream.

>>>/core/ (here is application)
>>>/core/doc ( here is the doc )
[quoted text clipped - 7 lines]
>>>I compress the application and doc in the jar file.
>>>I want to access to every dir or file recursively.

From within the same application? You don't. You use getResource() or
getResourceAsStream().

From outside the application? With the classes in java.util.jar.

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.