ブログ::=(メモ|落書き)帳

一人前になれないプログラマのメモと落書き

Eclipse Plug-inに含まれるFileの取得

Eclipseプラグイン開発でプラグイン内に静的にファイルをおいて、それを実行時に取得したいことがたまにある。 そんなときは以下のようにすれば、取得できる。

Bundle bundle = Activator.getDefault().getBundle();
URL fileUrl = bundle.getEntry("/resources/hoge.txt");
File file = null;
try {
    file = new File(FileLocator.resolve(fileUrl).toURI());
} catch(IOException | URISyntaxException e) {
    e.printStackTrace();
}

本ブログはAmazon.co.jpアソシエイトに参加しています