Here you can find the source of createFile(Path path)
Parameter | Description |
---|---|
path | the relative or absolute path of the file to create; may not be null |
public static File createFile(Path path)
//package com.java2s; /*//from w ww . j a v a 2 s. com * Copyright 2015 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ import java.io.File; import java.nio.file.Path; public class Main { /** * Create a file at the given absolute or relative path. * * @param path the relative or absolute path of the file to create; may not be null * @return the reference to the existing readable and writable file */ public static File createFile(Path path) { File file = path.toAbsolutePath().toFile(); if (file.exists() && file.canRead() && file.canWrite()) { if (file.isFile()) return file; throw new IllegalStateException("Expecting '" + path + "' to be a file but found a directory"); } file.getParentFile().mkdirs(); return file; } }