cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing a File in a Java Mapping

Former Member
0 Kudos

Hi,

I am accessing one Random Access File through Java Mapping Program. This is working fine in Eclipse.

But when I imported that jar file to IR, it is throwing FileNotFound Exception while trying to test through Interface Mapping.

I have bundled the file in the jar file, where the java class file is bundled.

Path to access the file from java program is "ProjectName/SomeName/File_Name.txt"

Can any one please help me in this regard?

Please help me to chase this mistery.

Thanks,

Yogi.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hello yogen,

once your file (or images) are inside a jar file, it cannot be accessed just like a

file. it is now a resource... to read a resource, try this simple reader.

InputStream is = getClass().getResourceAsStream(fileName); 
InputStreamReader isr = new InputStreamReader(is); 
BufferedReader br = new BufferedReader(isr);

regards

jo

Former Member
0 Kudos

Hi jo,

Thank you for your response.

I have one more issue. Please let me know how can I open a OutputStream and write to a file.

Thanks,

Yogi

Former Member
0 Kudos

hi yogen,

unfortunately you won't be able to directly write into a file that is within the jar file.

jar files are just like zip files and the files are compressed. you need to extract the

jar file, access and write the file, and re-zip (or jar) it once again. programmatically

this is possible, but you have to know the path of that jar file. if you are to modify

a file from your program, i would suggest not to include it inside a jar file. rather

put it outside to be accessed easily.

regards

jo

Answers (0)