Re: Read file in the jar file?



That's OK.
Thank you for your help.

Another problem.

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 file 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 under the jar file.



"pvii007" <pvii007@xxxxxxxxxxxx> дÈëÏûÏ¢ÐÂÎÅ:dndef5$r8g$1@xxxxxxxxxxxxxxxxx
> import java.io.*;
> public class A
> {
> public static void main( String[] args)throws Exception
> {
> A app = new A();
> BufferedReader bf = new BufferedReader(
> new InputStreamReader(app.getClass().getResourceAsStream("txt/b.txt"))
> );
> if( bf.ready())System.out.println(bf.readLine());
> }
> }
>
> Sorry It's still failure
>
> E:\code\java\test\jar\test>java -jar a.jar
> Exception in thread "main" java.lang.NullPointerException
> at java.io.Reader.<init>(Unknown Source)
> at java.io.InputStreamReader.<init>(Unknown Source)
> at A.main(A.java:7)
>
> "Alex" <akizub@xxxxxxxxx>
> ??????:1134169849.622062.308530@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>> My 2 cents.
>> 1) / is root of jar file. So, if it's in dir "dir" in jar it will be
>> OK.
>> 2) I dont't know why but you can't read files as resources from root
>> directly.
>> They must be in some directory.
>>
>> So, create jar with at least one directory "dir", place file here and
>> read it as
>> /dir/a.txt
>>
>> It works.
>>
>
>


.



Relevant Pages

  • Re: Soap Faults
    ... The Web Service encodes full server-side exception traces in the ... > I have had absolutely no luck working out how I can deserialize the custom ... > public string serverStackTraceId; ... > public class FdkExceptionEntry ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Create Outlook Contacts
    ... they cannot help further after the program shown no error exception and can ... public String getFirstName() { ... public void setMiddleNamethrows Exception { ... public String getBusinessPhoneNumber() { ...
    (microsoft.public.win32.programmer.messaging)
  • Re: HTTPUrlConnection does not download the whole page
    ... public String getPagethrows IOException { ... Certainly they should log the error before handling it, and if it must rethrow, often it's better to wrap the low-level exception in an application-specific exception. ... An alternative formulation for the loop that restricts the scope of 'line' to just the loop is: ...
    (comp.lang.java.help)
  • Re: Unable to execute program using the jar option.
    ... by specifying the class directly it runs just ... Exception: I believe the exact Exception is irrelevant to this issue ... path definately has the jar file that contains the class the exception ... complaining about finding the MigrationDirector .. ...
    (comp.lang.java.programmer)
  • Serialising soap faults
    ... The Web Service encodes full server-side exception traces in the ... FdkException fault= ser.Deserialize(new ... public string serverStackTraceId; ... Below is the SOAP message returned from the server on an invalid operation ...
    (microsoft.public.dotnet.framework.webservices)