If I have a constructor that requires a path to a file, how can I “fake” that if it is packaged into a jar?

前端 未结 6 1447
半阙折子戏
半阙折子戏 2020-12-17 05:09

The context of this question is that I am trying to use the maxmind java api in a pig script that I have written... I do not think that knowing about either is necessary to

6条回答
  •  攒了一身酷
    2020-12-17 05:45

    This works for me.

    Assuming you have a package org.foo.bar.util that contains GeoLiteCity.dat

    URL fileURL = this.getClass().getResource("org/foo/bar/util/GeoLiteCity.dat");
    File geoIPData = new File(fileURL.toURI());
    LookupService cl = new LookupService(geoIPData, LookupService.GEOIP_MEMORY_CACHE );
    

提交回复
热议问题