本文整理了Java中java.nio.file.Path.getParent()
方法的一些代码示例,展示了Path.getParent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Path.getParent()
方法的具体详情如下:
包路径:java.nio.file.Path
类名称:Path
方法名:getParent
暂无
代码示例来源:origin: jenkinsci/jenkins
private @CheckForNull Path getDirectChild(Path parentPath, String childPath){
Path current = parentPath.resolve(childPath);
while (current != null && !parentPath.equals(current.getParent())) {
current = current.getParent();
}
return current;
}
}
代码示例来源:origin: pxb1988/dex2jar
public static void createParentDirectories(Path p) throws IOException {
// merge patch from t3stwhat, fix crash on save to windows path like 'C:\\abc.jar'
Path parent = p.getParent();
if (parent != null && !Files.exists(parent)) {
Files.createDirectories(parent);
}
}
代码示例来源:origin: prestodb/presto
public static void writePluginServices(Iterable<String> plugins, File root)
throws IOException
{
Path path = root.toPath().resolve(SERVICES_FILE);
createDirectories(path.getParent());
try (Writer out = new OutputStreamWriter(new FileOutputStream(path.toFile()), UTF_8)) {
for (String plugin : plugins) {
out.write(plugin + "\n");
}
}
}
代码示例来源:origin: wildfly/wildfly
private Path tempPath() {
Path parent = path.getParent();
File file = parent.toFile();
if (!file.exists()) {
file.mkdirs();
}
return parent.resolve(path.getFileName().toString() + '.' + tempSuffix());
}
代码示例来源:origin: apache/ignite
/**
* Returns parent directory for the specified path.
*
* @param path Path.
* @return Parent directory path.
*/
private String getParent(String path) {
Path parentPath = Paths.get(path).getParent();
return parentPath == null ? null : parentPath.toString();
}
代码示例来源:origin: neo4j/neo4j
@Override
public File[] listFiles( File directory, final FilenameFilter filter )
{
try ( Stream<Path> listing = Files.list( path( directory ) ) )
{
return listing
.filter( entry -> filter.accept( entry.getParent().toFile(), entry.getFileName().toString() ) )
.map( Path::toFile )
.toArray( File[]::new );
}
catch ( IOException e )
{
return null;
}
}
代码示例来源:origin: Alluxio/alluxio
/**
* Creates an empty file and its intermediate directories if necessary.
*
* @param filePath pathname string of the file to create
*/
public static void createFile(String filePath) throws IOException {
Path storagePath = Paths.get(filePath);
Files.createDirectories(storagePath.getParent());
Files.createFile(storagePath);
}
代码示例来源:origin: apache/flink
@Override
protected String convertFromString(final String value) throws ConversionException {
final Path path = Paths.get(value);
if (path.getParent() != null) {
throw new ConversionException(String.format("%s must be a filename only (%s)", KEY, path));
}
return value;
}
代码示例来源:origin: ata4/disunity
outputDir = file.getParent();
if (outputDir == null) {
outputDir = Paths.get(".");
.forEach(uncheck(entry -> {
progress.update(Optional.of(entry.name()), done.getAndIncrement() / (double) total);
Path entryFile = outputDir.resolve(entry.name());
Files.createDirectories(entryFile.getParent());
Files.copy(entry.inputStream(), entryFile, REPLACE_EXISTING);
String bundleName = outputDir.getFileName().toString();
Path propsFile = outputDir.getParent().resolve(bundleName + ".json");
BundleProps.write(propsFile, bundle);
代码示例来源:origin: twosigma/beakerx
private String getSparkexJar() {
try {
Path path = Paths.get(EnableSparkSupportMagicCommand.class.getProtectionDomain().getCodeSource().getLocation().toURI());
return path.getParent().getParent().getParent().resolve("sparkex").resolve("lib").resolve("sparkex.jar").toString();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
static void createJar(final URI jarURI, final File workDir, final File f) throws Exception {
final Map<String, String> env = new HashMap<>();
env.put("create", "true");
final URI uri = URI.create("jar:file://" + jarURI.getRawPath());
try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
final Path path = zipfs.getPath(workDir.toPath().relativize(f.toPath()).toString());
if (path.getParent() != null) {
Files.createDirectories(path.getParent());
}
Files.copy(f.toPath(),
path,
StandardCopyOption.REPLACE_EXISTING );
}
}
代码示例来源:origin: bwssytems/ha-bridge
public String deleteBackup(String aFilename) {
log.debug("Delete backup repository: " + aFilename);
try {
Files.delete(FileSystems.getDefault().getPath(repositoryPath.getParent().toString(), aFilename));
} catch (IOException e) {
log.error("Could not delete file: " + aFilename + " message: " + e.getMessage(), e);
}
return aFilename;
}
代码示例来源:origin: uber/okbuck
public void finalizeDependencies() {
if (realBuckBinaryPath != null) {
Path linkedBinaryPath =
rootProject.file(BUCK_BINARY_LOCATION).toPath().resolve(realBuckBinaryPath.getFileName());
// Delete already existing folder
FileUtil.deleteQuietly(linkedBinaryPath.getParent());
// Make dirs
linkedBinaryPath.getParent().toFile().mkdirs();
FileUtil.symlink(linkedBinaryPath, realBuckBinaryPath);
}
}
}
代码示例来源:origin: MovingBlocks/Terasology
private void ensureDirectoryExists(Path filePath) {
try {
Files.createDirectories(filePath.getParent());
} catch (Exception e) {
throw new RuntimeException("Cannot create directory for flexibleConfig " + filePath.getFileName() + "!");
}
}
代码示例来源:origin: wildfly/wildfly
public AtomicFileOutputStream(final Path path) throws IOException {
final Path parent = path.getParent();
if (parent != null && parent.getNameCount() != 0 && ! Files.exists(parent)) {
Files.createDirectories(parent);
}
current = new OpenState(Files.newOutputStream(path.resolveSibling(path.getFileName() + ".new"), CREATE, TRUNCATE_EXISTING), path);
}
代码示例来源:origin: jmxtrans/jmxtrans
public FileWriter(@JsonProperty("typeNames") ImmutableList<String> typeNames,
@JsonProperty("booleanAsNumber") boolean booleanAsNumber,
@JsonProperty("debug") Boolean debugEnabled,
@JsonProperty(PROPERTY_BASEPATH) String filepath,
@JsonProperty(PROPERTY_LINE_FORMAT) String lineFormat,
@JsonProperty("resultSerializer") ResultSerializer resultSerializer,
@JsonProperty("settings") Map<String, Object> settings) throws IOException {
super(typeNames, booleanAsNumber, debugEnabled, settings);
this.outputFile = new File(filepath);
Path outputFilePath = outputFile.toPath();
this.outputTempFile = new File(outputFilePath.getParent() + File.separator + "." + outputFilePath.getFileName());
if (resultSerializer == null) {
if (lineFormat == null) {
this.resultSerializer= KeyValueResultSerializer.createDefault(typeNames);
} else {
this.resultSerializer= new KeyValueResultSerializer(lineFormat, typeNames);
}
} else {
if (lineFormat != null) {
log.warn("Both lineFormat and resultSerializer are defined, lineFormat will be ignored");
}
this.resultSerializer= resultSerializer;
}
// make sure the permissions allow to manage these files:
touch(this.outputFile);
touch(this.outputTempFile);
}
代码示例来源:origin: neo4j/neo4j
Path zipFsPath = fileSystem.isDirectory( sourceToCompress ) ? zipFs.getPath( rootPath.relativize( sourcePath ).toString() )
: zipFs.getPath( sourcePath.getFileName().toString() );
if ( zipFsPath.getParent() != null )
Files.createDirectories( zipFsPath.getParent() );
代码示例来源:origin: alibaba/canal
private String getJarDirectoryPath() {
URL url = Thread.currentThread().getContextClassLoader().getResource("");
String dirtyPath;
if (url != null) {
dirtyPath = url.toString();
} else {
File file = new File("");
dirtyPath = file.getAbsolutePath();
}
String jarPath = dirtyPath.replaceAll("^.*file:/", ""); // removes
// file:/ and
// everything
// before it
jarPath = jarPath.replaceAll("jar!.*", "jar"); // removes everything
// after .jar, if .jar
// exists in dirtyPath
jarPath = jarPath.replaceAll("%20", " "); // necessary if path has
// spaces within
if (!jarPath.endsWith(".jar")) { // this is needed if you plan to run
// the app using Spring Tools Suit play
// button.
jarPath = jarPath.replaceAll("/classes/.*", "/classes/");
}
return Paths.get(jarPath).getParent().toString(); // Paths - from java 8
}
代码示例来源:origin: apache/nifi
protected static String calculateDefaultOutputDirectory(Path currentPath) {
Path currentAbsolutePath = currentPath.toAbsolutePath();
Path parent = currentAbsolutePath.getParent();
if (currentAbsolutePath.getRoot().equals(parent)) {
return parent.toString();
} else {
Path currentNormalizedPath = currentAbsolutePath.normalize();
return "../" + currentNormalizedPath.getFileName().toString();
}
}
代码示例来源:origin: traccar/traccar
private File createFile(String uniqueId, String name) throws IOException {
Path filePath = Paths.get(path, uniqueId, name);
Path directoryPath = filePath.getParent();
if (directoryPath != null) {
Files.createDirectories(directoryPath);
}
return filePath.toFile();
}
内容来源于网络,如有侵权,请联系作者删除!