referencing data files in jars

后端 未结 3 1478
深忆病人
深忆病人 2021-01-28 18:52

My Java program references a lot of data files. I put them in a top level directory called data/, along with src/ and bin/. In Eclipse, references to data/ and ../data/ both s

3条回答
  •  庸人自扰
    2021-01-28 19:07

    If your resources are in a jar file, consider using this method to read them:

    class Class {
        InputStream getResourceAsStream(String name)
    }
    

    This looks for the resource relative to a class (which may be in a jar), rather than relative to the working directory.

提交回复
热议问题