本文整理了Java中java.nio.file.Files.createDirectory()
方法的一些代码示例,展示了Files.createDirectory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.createDirectory()
方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:createDirectory
暂无
代码示例来源:origin: robolectric/robolectric
public Path createIfNotExists(String name) {
Path path = basePath.resolve(name);
try {
Files.createDirectory(path);
} catch (FileAlreadyExistsException e) {
// that's ok
return path;
} catch (IOException e) {
throw new RuntimeException(e);
}
return path;
}
代码示例来源:origin: jenkinsci/jenkins
private void addEmptyUsernameIfExists(Map<String, File> users) throws IOException {
File emptyUsernameConfigFile = new File(usersDirectory, User.CONFIG_XML);
if (emptyUsernameConfigFile.exists()) {
File newEmptyUsernameDirectory = new File(usersDirectory, EMPTY_USERNAME_DIRECTORY_NAME);
Files.createDirectory(newEmptyUsernameDirectory.toPath());
File newEmptyUsernameConfigFile = new File(newEmptyUsernameDirectory, User.CONFIG_XML);
Files.move(emptyUsernameConfigFile.toPath(), newEmptyUsernameConfigFile.toPath());
users.put("", newEmptyUsernameDirectory);
}
}
代码示例来源:origin: robolectric/robolectric
public Path create(String name) {
Path path = basePath.resolve(name);
try {
Files.createDirectory(path);
} catch (IOException e) {
throw new RuntimeException(e);
}
return path;
}
代码示例来源:origin: jenkinsci/jenkins
private File createUsersDirectoryAsNeeded() throws IOException {
File usersDirectory = getUsersDirectory();
if (!usersDirectory.exists()) {
try {
Files.createDirectory(usersDirectory.toPath());
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Unable to create users directory: " + usersDirectory, e);
throw e;
}
}
return usersDirectory;
}
代码示例来源:origin: Alluxio/alluxio
/**
* Creates a new local Alluxio master with a isolated port.
*
* @param workDirectory Alluxio work directory, this method will create it if it doesn't exist yet
* @return the created Alluxio master
*/
public static LocalAlluxioMaster create(final String workDirectory) throws IOException {
if (!Files.isDirectory(Paths.get(workDirectory))) {
Files.createDirectory(Paths.get(workDirectory));
}
return new LocalAlluxioMaster(null, null);
}
代码示例来源:origin: SonarSource/sonarqube
public static DefaultInputModule newDefaultInputModule(AbstractProjectOrModule parent, String key) throws IOException {
Path basedir = parent.getBaseDir().resolve(key);
Files.createDirectory(basedir);
return newDefaultInputModule(key, basedir.toFile());
}
代码示例来源:origin: google/guava
@CanIgnoreReturnValue
private Path newDir(String name) throws IOException {
Path dir = rootDir.resolve(name);
Files.createDirectory(dir);
return dir;
}
代码示例来源:origin: neo4j/neo4j
@Override
public boolean mkdir( File fileName )
{
if ( !fileExists( fileName ) )
{
try
{
Files.createDirectory( path( fileName ) );
return true;
}
catch ( IOException ignore )
{
}
}
return false;
}
代码示例来源:origin: google/guava
@Override
public void run() {
boolean createSymlink = false;
while (!Thread.interrupted()) {
try {
// trying to switch between a real directory and a symlink (dir -> /a)
if (Files.deleteIfExists(file)) {
if (createSymlink) {
Files.createSymbolicLink(file, target);
} else {
Files.createDirectory(file);
}
createSymlink = !createSymlink;
}
} catch (IOException tolerated) {
// it's expected that some of these will fail
}
Thread.yield();
}
}
});
代码示例来源:origin: prestodb/presto
private static String prepareCassandraYaml()
throws IOException
{
String original = Resources.toString(getResource("cu-cassandra.yaml"), UTF_8);
File tempDirFile = createTempDir();
tempDirFile.deleteOnExit();
Path tmpDirPath = tempDirFile.toPath();
Path dataDir = tmpDirPath.resolve("data");
Files.createDirectory(dataDir);
String modified = original.replaceAll("\\$\\{data_directory\\}", dataDir.toAbsolutePath().toString());
Path yamlLocation = tmpDirPath.resolve("cu-cassandra.yaml");
write(modified, yamlLocation.toFile(), UTF_8);
return yamlLocation.toAbsolutePath().toString();
}
代码示例来源:origin: google/guava
@Override
public void setUp() throws IOException {
rootDir = Jimfs.newFileSystem(Configuration.unix()).getPath("/tmp");
Files.createDirectory(rootDir);
}
代码示例来源:origin: SonarSource/sonarqube
public static DefaultInputDir newDefaultInputDir(AbstractProjectOrModule module, String relativePath) throws IOException {
Path basedir = module.getBaseDir().resolve(relativePath);
Files.createDirectory(basedir);
return new DefaultInputDir(module.key(), relativePath)
.setModuleBaseDir(module.getBaseDir());
}
代码示例来源:origin: google/guava
@AndroidIncompatible // Path (for symlink creation)
public void testScanDirectory_symlinkToRootCycle() throws IOException {
ClassLoader loader = ClassPathTest.class.getClassLoader();
// directory with a cycle,
// /root
// /child
// /[grandchild -> root]
java.nio.file.Path root = createTempDirectory("ClassPathTest");
try {
createFile(root.resolve("some.txt"));
java.nio.file.Path child = createDirectory(root.resolve("child"));
createSymbolicLink(child.resolve("grandchild"), root);
ClassPath.DefaultScanner scanner = new ClassPath.DefaultScanner();
scanner.scan(root.toFile(), loader);
assertEquals(ImmutableSet.of(new ResourceInfo("some.txt", loader)), scanner.getResources());
} finally {
deleteRecursivelyOrLog(root);
}
}
代码示例来源:origin: google/guava
@AndroidIncompatible // Path (for symlink creation)
public void testScanDirectory_symlinkCycle() throws IOException {
ClassLoader loader = ClassPathTest.class.getClassLoader();
// directory with a cycle,
// /root
// /left
// /[sibling -> right]
// /right
// /[sibling -> left]
java.nio.file.Path root = createTempDirectory("ClassPathTest");
try {
java.nio.file.Path left = createDirectory(root.resolve("left"));
createFile(left.resolve("some.txt"));
java.nio.file.Path right = createDirectory(root.resolve("right"));
createFile(right.resolve("another.txt"));
createSymbolicLink(left.resolve("sibling"), right);
createSymbolicLink(right.resolve("sibling"), left);
ClassPath.DefaultScanner scanner = new ClassPath.DefaultScanner();
scanner.scan(root.toFile(), loader);
assertEquals(
ImmutableSet.of(
new ResourceInfo("left/some.txt", loader),
new ResourceInfo("left/sibling/another.txt", loader),
new ResourceInfo("right/another.txt", loader),
new ResourceInfo("right/sibling/some.txt", loader)),
scanner.getResources());
} finally {
deleteRecursivelyOrLog(root);
}
}
代码示例来源:origin: google/guava
public void testByteSource_size_ofDirectory() throws IOException {
try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) {
Path dir = fs.getPath("dir");
Files.createDirectory(dir);
ByteSource source = MoreFiles.asByteSource(dir);
assertThat(source.sizeIfKnown()).isAbsent();
try {
source.size();
fail();
} catch (IOException expected) {
}
}
}
代码示例来源:origin: google/guava
public void testByteSource_size_ofSymlinkToDirectory() throws IOException {
try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) {
Path dir = fs.getPath("dir");
Files.createDirectory(dir);
Path link = fs.getPath("link");
Files.createSymbolicLink(link, dir);
ByteSource source = MoreFiles.asByteSource(link);
assertThat(source.sizeIfKnown()).isAbsent();
try {
source.size();
fail();
} catch (IOException expected) {
}
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void should_not_delete_report_if_property_is_set() throws IOException {
when(properties.shouldKeepReport()).thenReturn(true);
Path reportDir = temp.getRoot().toPath().resolve("scanner-report");
Files.createDirectory(reportDir);
underTest.start();
underTest.stop();
assertThat(reportDir).isDirectory();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void should_delete_report_by_default() throws IOException {
Path reportDir = temp.getRoot().toPath().resolve("scanner-report");
Files.createDirectory(reportDir);
underTest.start();
underTest.stop();
assertThat(reportDir).doesNotExist();
}
代码示例来源:origin: google/guava
public void testPredicates() throws IOException {
Path file = createTempFile();
Path dir = tempDir.resolve("dir");
Files.createDirectory(dir);
assertTrue(MoreFiles.isDirectory().apply(dir));
assertFalse(MoreFiles.isRegularFile().apply(dir));
assertFalse(MoreFiles.isDirectory().apply(file));
assertTrue(MoreFiles.isRegularFile().apply(file));
Path symlinkToDir = tempDir.resolve("symlinkToDir");
Path symlinkToFile = tempDir.resolve("symlinkToFile");
Files.createSymbolicLink(symlinkToDir, dir);
Files.createSymbolicLink(symlinkToFile, file);
assertTrue(MoreFiles.isDirectory().apply(symlinkToDir));
assertFalse(MoreFiles.isRegularFile().apply(symlinkToDir));
assertFalse(MoreFiles.isDirectory().apply(symlinkToFile));
assertTrue(MoreFiles.isRegularFile().apply(symlinkToFile));
assertFalse(MoreFiles.isDirectory(NOFOLLOW_LINKS).apply(symlinkToDir));
assertFalse(MoreFiles.isRegularFile(NOFOLLOW_LINKS).apply(symlinkToFile));
}
代码示例来源:origin: Alluxio/alluxio
private AlluxioURI createPersistedDirectories(int levels) throws Exception {
AlluxioURI ufsMount = new AlluxioURI(mTestFolder.newFolder().getAbsolutePath());
// Create top-level directory in UFS.
Files.createDirectory(Paths.get(ufsMount.join(DIR_TOP_LEVEL).getPath()));
createPersistedDirectoryLevel(levels, ufsMount.join(DIR_TOP_LEVEL));
return ufsMount;
}
内容来源于网络,如有侵权,请联系作者删除!