referencing data files in jars

后端 未结 3 1442
深忆病人
深忆病人 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条回答
  •  -上瘾入骨i
    2021-01-28 19:22

    I'd recommend you access the files in a classpath-relative way, whether in Eclipse or in a compiled JAR.

    There are a few ways you might go about it, but a basic JDK-only approach would be to use Class's getResourceAsStream() method, giving you access to an InputStream object that you can read in.

提交回复
热议问题