aspose file tools
The moose likes Java in General and the fly likes Reading excel file inside jar file using jxl api not working !! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Reading excel file inside jar file using jxl api not working !!" Watch "Reading excel file inside jar file using jxl api not working !!" New topic
Author

Reading excel file inside jar file using jxl api not working !!

Rakhee Atri ,78
Greenhorn

Joined: Jul 11, 2006
Posts: 2
Hi,
Can any body help me?

I am running mfc.jar file from path: D:\Nidhi\final\.

This jar file contains package mfcalculator and mfcreport.xls file. So
excel file is outside mfcalculator.
I am reading this xls file in mfcalculator\Report.java by following code:

Workbook template = Workbook.getWorkbook(new File("mfcreport.xls"));

This work fine if I run class file but gives I/O exception as mfcreport.xls inside jar can not be read .
If I put mfcreport.xls in the same directory where my jar file is,it detects excel file.

Is there any way to wrap excel file inside jar file?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35223
    
    7
Welcome to JavaRanch.

You can obtain an InputStream representing a file within a jar file by using

getClass().getResourceAsStream(String)

The InputStream can then be passed to the

Workbook.getWorkbook(java.io.InputStream) method


Android appsImageJ pluginsJava web charts
Rakhee Atri ,78
Greenhorn

Joined: Jul 11, 2006
Posts: 2
Thanks for giving prompt reply.
It worked perfectly.

Again,similiar sort of problem I am facing,when I have to execute "MAC.vbs"
file again in jar.
I have tried two ways:

Using URL to get File Object.

URL url = getClass().getResource("MAC.vbs");
URI uri = url.toURI();
File filename = new File(uri);

Using string "File name"

Relevant Code is :

String filenam = getClass().getResource("MAC.vbs").getFile().replaceAll("%20", " ") ;

File filename = new File(filenam);

Process p = Runtime.getRuntime().exec("WScript.exe " + filenam);
Process p1 = Runtime.getRuntime().exec("rundll32 SHELL32.DLL, ShellExec_RunDLL " + filename.getAbsolutePath());

But I am getting errors for both.

Can u pl. tell me the way out?
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Reading excel file inside jar file using jxl api not working !!
 
Similar Threads
Adding an external jar file library in Netbeans 6.5.1 IDE
[URGENT] Reading a properties file from in an web application
importing jar to java class.......
excel file opening,editing and saving
How to give seperate file names for xls reports genetared usinf POI