我需要将一个Excel文件添加到我的jar包中,以便它可以移植。我知道答案是使用getClass().getResource...,但我不知道如何使用这段代码。
我的Excel文件在src文件夹中与我的类文件一起,它在NetBeans中工作,但在另一台电脑上打开jar文件时却出现了FileNotFoundException异常。
这是我所使用的代码:
public class WindageLogic {
//....
public void GetValues() throws Exception
{
File exel=new File("src/Calculator/table1.xls");
Workbook w1; //reads from file
//reads from file
w1 = Workbook.getWorkbook(exel);
有人能给我提供代码吗?我想实现从jar应用程序中访问此文件。我已经在网上寻找了整个周末,但是我不懂如何使用这些getresource技术。
非常感谢。