當前位置: 首頁>>代碼示例>>Java>>正文


Java Files.createSymbolicLink方法代碼示例

本文整理匯總了Java中java.nio.file.Files.createSymbolicLink方法的典型用法代碼示例。如果您正苦於以下問題:Java Files.createSymbolicLink方法的具體用法?Java Files.createSymbolicLink怎麽用?Java Files.createSymbolicLink使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.file.Files的用法示例。


在下文中一共展示了Files.createSymbolicLink方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: test

import java.nio.file.Files; //導入方法依賴的package包/類
void test(Path base, String name) throws IOException {
    Path file = base.resolve(name);
    Path javaFile = base.resolve("HelloWorld.java");
    tb.writeFile(file,
            "public class HelloWorld {\n"
            + "    public static void main(String... args) {\n"
            + "        System.err.println(\"Hello World!\");\n"
            + "    }\n"
            + "}");

    try {
        Files.createSymbolicLink(javaFile, file.getFileName());
    } catch (FileSystemException fse) {
        System.err.println("warning: test passes vacuously, sym-link could not be created");
        System.err.println(fse.getMessage());
        return;
    }

    Path classes = Files.createDirectories(base.resolve("classes"));
    new JavacTask(tb)
        .outdir(classes)
        .files(javaFile)
        .run()
        .writeAll();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:SymLinkTest.java

示例2: testIndirectSymbolicLink

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Test directory tree with a indirect cyclic link.
 * <pre>
 *  a
 *    b
 *      c ( -> a)
 *    d
 *      e ( -> c)
 * </pre>
 *
 * @throws java.io.IOException
 */
public void testIndirectSymbolicLink() throws IOException {
    File a = new File(getWorkDir(), "a");
    File b = new File(a, "b");
    File c = new File(b, "c");
    File d = new File(a, "d");
    File e = new File(d, "e");
    assertTrue(b.mkdirs());
    assertTrue(d.mkdirs());
    try {
        Files.createSymbolicLink(c.toPath(), a.toPath());
        Files.createSymbolicLink(e.toPath(), c.toPath());
        FileObject fo = FileUtil.toFileObject(getWorkDir());
        assertEquals(3, countRecursiveChildren(fo));
    } catch (IOException ex) {
        printSkipped();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:FileObjectCyclicSymlinksTest.java

示例3: testEqual_links

import java.nio.file.Files; //導入方法依賴的package包/類
public void testEqual_links() throws IOException {
  try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) {
    Path fooPath = fs.getPath("foo");
    MoreFiles.asCharSink(fooPath, UTF_8).write("foo");

    Path fooSymlink = fs.getPath("symlink");
    Files.createSymbolicLink(fooSymlink, fooPath);

    Path fooHardlink = fs.getPath("hardlink");
    Files.createLink(fooHardlink, fooPath);

    assertThat(MoreFiles.equal(fooPath, fooSymlink)).isTrue();
    assertThat(MoreFiles.equal(fooPath, fooHardlink)).isTrue();
    assertThat(MoreFiles.equal(fooSymlink, fooHardlink)).isTrue();
  }
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:17,代碼來源:MoreFilesTest.java

示例4: main

import java.nio.file.Files; //導入方法依賴的package包/類
public static void main(String... args) throws Exception {
    ToolBox tb = new ToolBox();
    tb.writeFile("tmp/B.java", BSrc);

    // Try to set up a symbolic link for the test.
    try {
        Files.createSymbolicLink(Paths.get("a"), Paths.get("tmp"));
        System.err.println("Created symbolic link");
    } catch (UnsupportedOperationException | IOException e) {
        System.err.println("Problem creating symbolic link: " + e);
        System.err.println("Test cannot continue; test passed by default");
        return;
    }

    // If symbolic link was successfully created,
    // try a compilation that will use it.
    new JavacTask(tb)
            .sourcepath(".")
            .outdir(".")
            .sources(TSrc)
            .run()
            .writeAll();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:LinksTest.java

示例5: mkSymlink

import java.nio.file.Files; //導入方法依賴的package包/類
public void mkSymlink(String symlinkName, String symlinkTarget) throws StorageAdapterException {
    try {
        File link = new File(symlinkName);
        File target = new File(symlinkTarget);

        mkParentDirs(link); // make sure directory containing the link exists
        Files.createSymbolicLink(link.toPath(), target.toPath());
    } catch (Exception e) {
        String errMsg = e.getMessage();
        if (e instanceof FileAlreadyExistsException) {
            errMsg = "the file already exists";
        }
        errMsg = String.format("Error creating symlink %s to target %s: %s", symlinkName,
                               symlinkTarget, errMsg);
        LOG.log(Level.WARNING, errMsg, e);
        throw new StorageAdapterException(errMsg, e);
    }
}
 
開發者ID:Hitachi-Data-Systems,項目名稱:Open-DM,代碼行數:19,代碼來源:FileSystemAdapter.java

示例6: testByteSource_size_ofSymlinkToRegularFile_nofollowLinks

import java.nio.file.Files; //導入方法依賴的package包/類
public void testByteSource_size_ofSymlinkToRegularFile_nofollowLinks() throws IOException {
  try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) {
    Path file = fs.getPath("file");
    Files.write(file, new byte[10]);
    Path link = fs.getPath("link");
    Files.createSymbolicLink(link, file);

    ByteSource source = MoreFiles.asByteSource(link, NOFOLLOW_LINKS);

    assertThat(source.sizeIfKnown()).isAbsent();

    try {
      source.size();
      fail();
    } catch (IOException expected) {
    }
  }
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:19,代碼來源:MoreFilesTest.java

示例7: testAddMissingSymlink

import java.nio.file.Files; //導入方法依賴的package包/類
public void testAddMissingSymlink () throws Exception {
    if (isWindows()) {
        return;
    }
    String path = "folder/file";
    File f = new File(workDir, path);
    
    // try with commandline client
    File link = new File(workDir, "link");
    Files.createSymbolicLink(Paths.get(link.getAbsolutePath()), Paths.get(path));
    getClient(workDir).add(new File[] { link }, NULL_PROGRESS_MONITOR);
    DirCacheEntry e = repository.readDirCache().getEntry(link.getName());
    assertEquals(FileMode.SYMLINK, e.getFileMode());
    assertEquals(0, e.getLength());
    ObjectReader reader = repository.getObjectDatabase().newReader();
    assertTrue(reader.has(e.getObjectId()));
    byte[] bytes = reader.open(e.getObjectId()).getBytes();
    assertEquals(path, RawParseUtils.decode(bytes));
    reader.release();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:AddTest.java

示例8: testPredicates

import java.nio.file.Files; //導入方法依賴的package包/類
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));
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:27,代碼來源:MoreFilesTest.java

示例9: testIsRecursiveSymbolicLinkIndirect

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Test isRecursiveSymbolicLink method. Use this folder tree:
 * <pre>
 * - workdir
 *   - a
 *     - b
 *       - c (symlink to d)
 *   - d (symlink to a)
 * </pre>
 *
 * @throws java.io.IOException
 */
public void testIsRecursiveSymbolicLinkIndirect() throws IOException {
    if (!checkSymlinksSupported()) {
        return;
    }
    File dir = getWorkDir();
    File a = new File(dir, "a");
    File b = new File(a, "b");
    File c = new File(b, "c");
    File d = new File(dir, "d");
    b.mkdirs();
    Files.createSymbolicLink(d.toPath(), a.toPath());
    Files.createSymbolicLink(c.toPath(), d.toPath());
    FileObject dirFO = FileUtil.toFileObject(dir);
    FileObject cFO = dirFO.getFileObject("a/b/c");
    assertTrue(FileUtil.isRecursiveSymbolicLink(cFO));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:29,代碼來源:FileObjSymlinkTest.java

示例10: testReadSymbolicLinkRelative

import java.nio.file.Files; //導入方法依賴的package包/類
public void testReadSymbolicLinkRelative() throws IOException {
    if (!checkSymlinksSupported()) {
        return;
    }
    File dir = getWorkDir();
    File folder = new File(dir, "folder");
    File link = new File(dir, "link");
    folder.mkdir();
    Path lp = Files.createSymbolicLink(link.toPath(), Paths.get("folder"));
    assertNotNull(lp);
    FileObject linkFO = FileUtil.toFileObject(link);
    assertNotNull(linkFO);
    FileObject dataFO = linkFO.readSymbolicLink();
    assertNotSame(linkFO, dataFO);
    assertNotNull(dataFO);
    assertEquals("folder", dataFO.getNameExt());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:FileObjSymlinkTest.java

示例11: testAllowedSymbolicLink

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Test allowed (non-cyclic) symlink.
 * <pre>
 * a
 *   b
 *     c ( -> d)
 *   d
 *     e
 *       f
 * </pre>
 *
 * @throws java.io.IOException
 */
public void testAllowedSymbolicLink() throws IOException {
    File a = new File(getWorkDir(), "a");
    File b = new File(a, "b");
    File c = new File(b, "c");
    File d = new File(a, "d");
    File e = new File(d, "e");
    File f = new File(e, "f");
    assertTrue(b.mkdirs());
    assertTrue(f.mkdirs());
    try {
        Files.createSymbolicLink(c.toPath(), d.toPath());
        assertEquals(3, countRecursiveChildren(FileUtil.toFileObject(b)));
    } catch (IOException ex) {
        printSkipped();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:30,代碼來源:FileObjectCyclicSymlinksTest.java

示例12: testByteSource_size_ofSymlinkToRegularFile

import java.nio.file.Files; //導入方法依賴的package包/類
public void testByteSource_size_ofSymlinkToRegularFile() throws IOException {
  try (FileSystem fs = Jimfs.newFileSystem(Configuration.unix())) {
    Path file = fs.getPath("file");
    Files.write(file, new byte[10]);
    Path link = fs.getPath("link");
    Files.createSymbolicLink(link, file);

    ByteSource source = MoreFiles.asByteSource(link);

    assertEquals(10L, (long) source.sizeIfKnown().get());
    assertEquals(10L, source.size());
  }
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:14,代碼來源:MoreFilesTest.java

示例13: symlink

import java.nio.file.Files; //導入方法依賴的package包/類
@Override
public void symlink(final Local file, final String target) throws AccessDeniedException {
    try {
        Files.createSymbolicLink(Paths.get(file.getAbsolute()), Paths.get(target));
    }
    catch(IOException | UnsupportedOperationException e) {
        throw new AccessDeniedException(String.format("%s %s",
                LocaleFactory.localizedString("Cannot create file", "Error"), file.getAbsolute()), e);
    }
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:11,代碼來源:DefaultSymlinkFeature.java

示例14: createSymbolicLink

import java.nio.file.Files; //導入方法依賴的package包/類
@Override
public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs)
    throws IOException
{
    triggerEx(target, "createSymbolicLink");
    Files.createSymbolicLink(unwrap(link), unwrap(target), attrs);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:FaultyFileSystem.java

示例15: testPidFile

import java.nio.file.Files; //導入方法依賴的package包/類
public void testPidFile() throws IOException {
    Path dir = createTempDir();
    Path parent = dir.resolve("foo");
    if (randomBoolean()) {
        Files.createDirectories(parent);
        if (randomBoolean()) {
            try {
                Path link = dir.resolve("link_to_real_path");
                Files.createSymbolicLink(link, parent.getFileName());
                parent = link;
            } catch (UnsupportedOperationException | IOException | SecurityException ex) {
               // fine - no links on this system
            }

        }
    }
    Path pidFile = parent.resolve("foo.pid");
    long pid = randomLong();
    if (randomBoolean() && Files.exists(parent)) {
        try (BufferedWriter stream = Files.newBufferedWriter(pidFile, StandardCharsets.UTF_8, StandardOpenOption.CREATE_NEW)) {
            stream.write("foo");
        }
    }

    final PidFile inst = PidFile.create(pidFile, false, pid);
    assertEquals(pidFile, inst.getPath());
    assertEquals(pid, inst.getPid());
    assertFalse(inst.isDeleteOnExit());
    assertTrue(Files.exists(pidFile));
    assertEquals(pid, Long.parseLong(new String(Files.readAllBytes(pidFile), StandardCharsets.UTF_8)));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:32,代碼來源:PidFileTests.java


注:本文中的java.nio.file.Files.createSymbolicLink方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。