referencing data files in jars

后端 未结 3 1476
深忆病人
深忆病人 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:25

    Thanks for pointing me down this path, guys. I ended up doing a really hacked up workaround because I'm not very good with IO yet. I used getClass() to construct a URL:

    http://forums.sun.com/thread.jspa?threadID=5258488

    Then made a new File object from this string (new File(file)):

    String file = url.toString().replaceFirst("file:", "");

    This allowed me to keep the same code that referenced the file objects.

提交回复
热议问题