How to list the files inside a JAR file?

前端 未结 16 2583
温柔的废话
温柔的废话 2020-11-22 00:40

I have this code which reads all the files from a directory.

    File textFolder = new File(\"text_directory\");

    File [] texFiles = textFolder.listFiles         


        
16条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 01:18

    public static ArrayList listItems(String path) throws Exception{
        InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream(path);
        byte[] b = new byte[in.available()];
        in.read(b);
        String data = new String(b);
        String[] s = data.split("\n");
        List a = Arrays.asList(s);
        ArrayList m = new ArrayList<>(a);
        return m;
    }
    

提交回复
热议问题