当前位置: 首页>>代码示例>>Java>>正文


Java Path.toRealPath方法代码示例

本文整理汇总了Java中java.nio.file.Path.toRealPath方法的典型用法代码示例。如果您正苦于以下问题:Java Path.toRealPath方法的具体用法?Java Path.toRealPath怎么用?Java Path.toRealPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.Path的用法示例。


在下文中一共展示了Path.toRealPath方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDeleteRecursively_nonDirectoryFile

import java.nio.file.Path; //导入方法依赖的package包/类
public void testDeleteRecursively_nonDirectoryFile() throws IOException {
  try (FileSystem fs = newTestFileSystem(SECURE_DIRECTORY_STREAM)) {
    Path file = fs.getPath("dir/a");
    assertTrue(Files.isRegularFile(file, NOFOLLOW_LINKS));

    MoreFiles.deleteRecursively(file);

    assertFalse(Files.exists(file, NOFOLLOW_LINKS));

    Path symlink = fs.getPath("/symlinktodir");
    assertTrue(Files.isSymbolicLink(symlink));

    Path realSymlinkTarget = symlink.toRealPath();
    assertTrue(Files.isDirectory(realSymlinkTarget, NOFOLLOW_LINKS));

    MoreFiles.deleteRecursively(symlink);

    assertFalse(Files.exists(symlink, NOFOLLOW_LINKS));
    assertTrue(Files.isDirectory(realSymlinkTarget, NOFOLLOW_LINKS));
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:22,代码来源:MoreFilesTest.java

示例2: btn_kontrolActionPerformed

import java.nio.file.Path; //导入方法依赖的package包/类
private void btn_kontrolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_kontrolActionPerformed
    // TODO add your handling code here:
     EntityManagerFactory emf = Persistence.createEntityManagerFactory("BP2_LAB2PU");
        EntityManager em = emf.createEntityManager();
        Query q = em.createQuery("SELECT m FROM Musteri m");
        List<Musteri> musteriler = q.getResultList();
    
    for (Musteri musteri : musteriler) {
         Path p= Paths.get("musteriler\\"+musteri.getId()+".txt");
         try {
             p.toRealPath();
         } catch (IOException ex) {
             System.out.println(musteri.getId()+" numaralı müsteri dosyası bulunamadı");
         }
    }
    
}
 
开发者ID:sametkaya,项目名称:Java_Swing_Programming,代码行数:18,代码来源:Soru1.java

示例3: pathToURLs

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Convert class path specification into an array of file URLs.
 *
 * The path of the file is converted to a URI then into URL
 * form so that reserved characters can safely appear in the path.
 */
private static URL[] pathToURLs(String path) {
    List<URL> paths = new ArrayList<>();
    for (String entry: path.split(File.pathSeparator)) {
        Path p = Paths.get(entry);
        try {
            p = p.toRealPath();
        } catch (IOException x) {
            p = p.toAbsolutePath();
        }
        try {
            paths.add(p.toUri().toURL());
        } catch (MalformedURLException e) {
            //ignore / skip entry
        }
    }
    return paths.toArray(new URL[0]);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:RegistryImpl.java

示例4: obtainLock

import java.nio.file.Path; //导入方法依赖的package包/类
@Override
public Lock obtainLock(@NonNull Directory dir, String lockName) throws IOException {
    if (!(dir instanceof RedisDirectory)) {
        throw new IllegalArgumentException("Expect argument of type [" + RedisDirectory.class.getName() + "]!");
    }
    Path lockFile = lockFileDirectory.resolve(lockName);
    try {
        Files.createFile(lockFile);
        log.debug("Lock file path = {}", lockFile.toFile().getAbsolutePath());
    } catch (IOException ignore) {
        //ignore
        log.debug("Lock file already exists!");
    }
    final Path realPath = lockFile.toRealPath();
    final FileTime creationTime = Files.readAttributes(realPath, BasicFileAttributes.class).creationTime();
    if (LOCK_HELD.add(realPath.toString())) {
        FileChannel fileChannel = null;
        FileLock lock = null;
        try {
            fileChannel = FileChannel.open(realPath, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
            lock = fileChannel.tryLock();
            if (lock != null) {
                return new RedisLock(lock, fileChannel, realPath, creationTime);
            } else {
                throw new LockObtainFailedException("Lock held by another program: " + realPath);
            }
        } finally {
            if (lock == null) {
                IOUtils.closeQuietly(fileChannel);
                clearLockHeld(realPath);
            }
        }
    } else {
        throw new LockObtainFailedException("Lock held by this virtual machine: " + realPath);
    }
}
 
开发者ID:shijiebei2009,项目名称:RedisDirectory,代码行数:37,代码来源:RedisLockFactory.java

示例5: jButton3ActionPerformed

import java.nio.file.Path; //导入方法依赖的package包/类
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
         EntityManagerFactory emf=Persistence.createEntityManagerFactory("BP2_LAB2PU");
         EntityManager em=emf.createEntityManager();
         Query q=em.createQuery("SELECT k FROM Personel k");
         List<Personel>personeller=q.getResultList();
      //   ArrayList<String> paths=new ArrayList();
         for (Personel personel : personeller) {
             try {
                 //   paths.add(personel.getAdi());
                 Path p =Paths.get(personel.getAdi());
                 p.toRealPath();
             } catch (IOException ex) {
                 Logger.getLogger(Soru2.class.getName()).log(Level.SEVERE, null, ex);
             }
        }
//         
//         for (String path : paths) {
//             try {
//                 Path p=Paths.get(path);
//                 p.toRealPath();
//             } catch (IOException ex) {
//                 System.out.println(path+" Müşterisine Ait Bilgi Bulunamadı.");
//             }
//        }
         
         
    }
 
开发者ID:sametkaya,项目名称:Java_Swing_Programming,代码行数:29,代码来源:Soru2.java

示例6: normalize

import java.nio.file.Path; //导入方法依赖的package包/类
static Path normalize(Path p) {
    try {
        return p.toRealPath();
    } catch (IOException e) {
        return p.toAbsolutePath().normalize();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:Locations.java

示例7: getCanonicalFile

import java.nio.file.Path; //导入方法依赖的package包/类
public Path getCanonicalFile(Path file) {
    try {
        return file.toRealPath();
    } catch (IOException e) {
        return file.toAbsolutePath().normalize();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:FSInfo.java

示例8: set

import java.nio.file.Path; //导入方法依赖的package包/类
/**
 * Helper to set a {@link Path} value correctly for use with {@link #overlayOn(Map,Config)}.
 *
 * @param overlay key-value pairs to overlay on a {@link Config}
 * @param key key to set
 * @param path {@link Path} value
 * @throws IOException if {@link Path} can't be made canonical
 */
public static void set(Map<String,Object> overlay, String key, Path path) throws IOException {
  Path finalPath = Files.exists(path, LinkOption.NOFOLLOW_LINKS) ?
      path.toRealPath(LinkOption.NOFOLLOW_LINKS) :
      path;
  overlay.put(key, "\"" + finalPath.toUri() + "\"");
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:15,代码来源:ConfigUtils.java


注:本文中的java.nio.file.Path.toRealPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。