Java Path File Name nio getPath(Class example, String filename)

Here you can find the source of getPath(Class example, String filename)

Description

get Path

License

Open Source License

Declaration

public static Path getPath(Class example, String filename) 

Method Source Code


//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
}

Related

  1. getName(String path)
  2. getNamePart(Path file)
  3. getNameWithoutSuffix(Path path)
  4. getNormalizedFileName(Path file)
  5. getPackageURI(String pkgName, String pkgPath, String currentPkgName)
  6. getPath(Class baseClass, String resourceName)
  7. getPath(File dir, String filename)
  8. getPath(final String fullFileName)
  9. getPath(Object name)