Here you can find the source of getPath(Class example, String filename)
public static Path getPath(Class example, String filename)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; public class Main { public static Path getPath(Class example, String filename) { final File f = new File(example.getProtectionDomain().getCodeSource().getLocation().getPath()); String path = f.getAbsolutePath(); int subPathIndex = path.indexOf("Examples"); String subPath = path.substring(0, subPathIndex) + "Data/" + filename; Path p = Paths.get(subPath); return p; }//from w ww .j a va2 s .com }