need help with jar archiv  
Author Message
Sunil Pilani





PostPosted: 2007-4-8 20:17:00 Top

java-programmer, need help with jar archiv Hi,
I need some help with my jar archive.
I need to read a file in my program. I do that with
FileReader.
To locate the file I use getClass().getResource("key/key.txt")
I used the above class.getResource so that teh programme locates the file
in the jar archive. But it doesn't work after getting packed in
jar, otherwise works perfectly alright.

I use the following command to make the jar:
jar cmf caesar/mainClass cipher.jar caesar/c*.class caesar/key/key.txt

Can somebody please help me with that.

I get a error-message as follows
file:\E:\myprogs\Security\cipher.jar!\caesar\key\key.txt ( The syntax for
the filename,
directory and data volume is wrong)
The relevant code lines:
URL fileUrl = getClass().getResource("key/key.txt");


// String filename = fileUrl.getFile();

System.out.println(fileUrl.getFile());

try {

System.out.println(fileUrl.getFile());

BufferedReader read =

new BufferedReader

(new FileReader(fileUrl.getFile()));


Regards,

Sunil



 
Sam Petrosa





PostPosted: 2007-4-9 1:49:00 Top

java-programmer >> need help with jar archiv help please!

"Sunil Pilani" <email***@***.com> schrieb im Newsbeitrag
news:dd4cb$4618dd35$54704fad$email***@***.com...
> Hi,
> I need some help with my jar archive.
> I need to read a file in my program. I do that with
> FileReader.
> To locate the file I use getClass().getResource("key/key.txt")
> I used the above class.getResource so that teh programme locates the file
> in the jar archive. But it doesn't work after getting packed in
> jar, otherwise works perfectly alright.
>
> I use the following command to make the jar:
> jar cmf caesar/mainClass cipher.jar caesar/c*.class caesar/key/key.txt
>
> Can somebody please help me with that.
>
> I get a error-message as follows
> file:\E:\myprogs\Security\cipher.jar!\caesar\key\key.txt ( The syntax for
> the filename,
> directory and data volume is wrong)
> The relevant code lines:
> URL fileUrl = getClass().getResource("key/key.txt");
>
>
> // String filename = fileUrl.getFile();
>
> System.out.println(fileUrl.getFile());
>
> try {
>
> System.out.println(fileUrl.getFile());
>
> BufferedReader read =
>
> new BufferedReader
>
> (new FileReader(fileUrl.getFile()));
>
>
> Regards,
>
> Sunil
>
>
>


 
Knute Johnson





PostPosted: 2007-4-9 1:59:00 Top

java-programmer >> need help with jar archiv Sunil Pilani wrote:
> Hi,
> I need some help with my jar archive.
> I need to read a file in my program. I do that with
> FileReader.
> To locate the file I use getClass().getResource("key/key.txt")
> I used the above class.getResource so that teh programme locates the file
> in the jar archive. But it doesn't work after getting packed in
> jar, otherwise works perfectly alright.
>
> I use the following command to make the jar:
> jar cmf caesar/mainClass cipher.jar caesar/c*.class caesar/key/key.txt
>
> Can somebody please help me with that.
>
> I get a error-message as follows
> file:\E:\myprogs\Security\cipher.jar!\caesar\key\key.txt ( The syntax for
> the filename,
> directory and data volume is wrong)
> The relevant code lines:
> URL fileUrl = getClass().getResource("key/key.txt");
>
>
> // String filename = fileUrl.getFile();
>
> System.out.println(fileUrl.getFile());
>
> try {
>
> System.out.println(fileUrl.getFile());
>
> BufferedReader read =
>
> new BufferedReader
>
> (new FileReader(fileUrl.getFile()));
>
>
> Regards,
>
> Sunil
>

Probably the simplest solution is to use a different method:

InputStream is = getClass().getResourceAsStream("key/key.txt");

You also need to be careful with the package names. Confirm that your
jar file actually contains key/key.txt and not something else.

--

Knute Johnson
email s/nospam/knute/
 
 
Sam Petrosa





PostPosted: 2007-4-9 6:05:00 Top

java-programmer >> need help with jar archiv Thanks!
I overlooked the stream method and had been
busy making it work by changing the directory structure,
altering the jar command, etc.

Regards,
Sunil

"Knute Johnson" <email***@***.com> schrieb im Newsbeitrag
news:L3aSh.434093$email***@***.com...
> Sunil Pilani wrote:
>> Hi,
>> I need some help with my jar archive.
>> I need to read a file in my program. I do that with
>> FileReader.
>> To locate the file I use getClass().getResource("key/key.txt")
>> I used the above class.getResource so that teh programme locates the file
>> in the jar archive. But it doesn't work after getting packed in
>> jar, otherwise works perfectly alright.
>>
>> I use the following command to make the jar:
>> jar cmf caesar/mainClass cipher.jar caesar/c*.class caesar/key/key.txt
>>
>> Can somebody please help me with that.
>>
>> I get a error-message as follows
>> file:\E:\myprogs\Security\cipher.jar!\caesar\key\key.txt ( The syntax for
>> the filename,
>> directory and data volume is wrong)
>> The relevant code lines:
>> URL fileUrl = getClass().getResource("key/key.txt");
>>
>>
>> // String filename = fileUrl.getFile();
>>
>> System.out.println(fileUrl.getFile());
>>
>> try {
>>
>> System.out.println(fileUrl.getFile());
>>
>> BufferedReader read =
>>
>> new BufferedReader
>>
>> (new FileReader(fileUrl.getFile()));
>>
>>
>> Regards,
>>
>> Sunil
>>
>
> Probably the simplest solution is to use a different method:
>
> InputStream is = getClass().getResourceAsStream("key/key.txt");
>
> You also need to be careful with the package names. Confirm that your jar
> file actually contains key/key.txt and not something else.
>
> --
>
> Knute Johnson
> email s/nospam/knute/