本文整理汇总了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));
}
}
示例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ı");
}
}
}
示例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]);
}
示例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);
}
}
示例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ı.");
// }
// }
}
示例6: normalize
import java.nio.file.Path; //导入方法依赖的package包/类
static Path normalize(Path p) {
try {
return p.toRealPath();
} catch (IOException e) {
return p.toAbsolutePath().normalize();
}
}
示例7: getCanonicalFile
import java.nio.file.Path; //导入方法依赖的package包/类
public Path getCanonicalFile(Path file) {
try {
return file.toRealPath();
} catch (IOException e) {
return file.toAbsolutePath().normalize();
}
}
示例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() + "\"");
}