how to access resources(Excel file) in jar file

后端 未结 4 1564
Happy的楠姐
Happy的楠姐 2020-12-21 05:27

Hi i have exported my java project as executable jar file. inside my project I am accessing a Excel file containing some data. Now I am not able to access the Excel file whe

4条回答
  •  悲哀的现实
    2020-12-21 06:28

    I tried this and it is working for me.

    My Test1 class is in default package, just check where your accessing class is in any package, if it is then go back to exact resource folder from classpath like this "../"

    public class Test1 {
    
        public static void main(String[] args) {
            new Test1();  
        }
        Test1(){
            BufferedInputStream file= (BufferedInputStream) this.getClass().getResourceAsStream("resources/a.txt");
            try {
                System.out.println((char)file.read());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    
    }
    

提交回复
热议问题