java.nio.file.FileSystems.getDefault()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(557)

本文整理了Java中java.nio.file.FileSystems.getDefault()方法的一些代码示例,展示了FileSystems.getDefault()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileSystems.getDefault()方法的具体详情如下:
包路径:java.nio.file.FileSystems
类名称:FileSystems
方法名:getDefault

FileSystems.getDefault介绍

暂无

代码示例

代码示例来源:origin: wildfly/wildfly

/**
 * Creates a FileSystemXAResourceRegistry.
 *
 * @param relativePath the path recovery dir is relative to
 */
FileSystemXAResourceRegistry (LocalTransactionProvider provider, Path relativePath) {
  this.provider = provider;
  if (relativePath == null)
     this.xaRecoveryPath = FileSystems.getDefault().getPath(RECOVERY_DIR);
  else
    this.xaRecoveryPath = relativePath.resolve(RECOVERY_DIR);
}

代码示例来源:origin: jphp-group/jphp

@Signature(@Arg("pattern"))
public Memory matches(Environment env, Memory... args) {
  FileSystem aDefault = FileSystems.getDefault();
  PathMatcher pathMatcher = aDefault.getPathMatcher(args[0].toString());
  return pathMatcher.matches(aDefault.getPath(file.getPath())) ? Memory.TRUE : Memory.FALSE;
}

代码示例来源:origin: stackoverflow.com

import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

// ...
    Path p = FileSystems.getDefault().getPath("", "myFile");
    byte [] fileData = Files.readAllBytes(p);

代码示例来源:origin: Netflix/conductor

default File createDataDir(String dataDirLoc) throws IOException {
  Path dataDirPath = FileSystems.getDefault().getPath(dataDirLoc);
  Files.createDirectories(dataDirPath);
  return dataDirPath.toFile();
}

代码示例来源:origin: biezhi/30-seconds-of-java8

public static String getCurrentWorkingDirectoryPath() {
  return FileSystems.getDefault().getPath("").toAbsolutePath().toString();
}

代码示例来源:origin: bwssytems/ha-bridge

public String deleteBackup(String aFilename) {
  log.debug("Delete backup repository: " + aFilename);
  try {
    Files.delete(FileSystems.getDefault().getPath(repositoryPath.getParent().toString(), aFilename));
  } catch (IOException e) {
    log.error("Could not delete file: " + aFilename + " message: " + e.getMessage(), e);
  }
  return aFilename;
}

代码示例来源:origin: apache/zeppelin

public void watch(File file) throws IOException {
 String dirString;
 if (file.isFile()) {
  dirString = file.getParentFile().getAbsolutePath();
 } else {
  throw new IOException(file.getName() + " is not a file");
 }
 if (dirString == null) {
  dirString = "/";
 }
 Path dir = FileSystems.getDefault().getPath(dirString);
 logger.info("watch " + dir);
 WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
 synchronized (watchKeys) {
  watchKeys.put(key, new File(dirString));
  watchFiles.add(file);
 }
}

代码示例来源:origin: spotify/helios

public static <T> PersistentAtomicReference<T> create(final String filename,
                           final JavaType javaType,
                           final Supplier<? extends T> initialValue)
  throws IOException, InterruptedException {
 return create(FileSystems.getDefault().getPath(filename), javaType, initialValue);
}

代码示例来源:origin: apache/ignite

/**
   * @param url URL or path to check and convert to URL.
   * @return URL.
   * @throws SQLException If URL is invalid.
   */
  private static String checkAndConvertUrl(String url) throws SQLException {
    try {
      return new URL(url).toString();
    }
    catch (MalformedURLException e) {
      try {
        return FileSystems.getDefault().getPath(url).toUri().toURL().toString();
      }
      catch (MalformedURLException e1) {
        throw new SQLException("Invalid keystore UR: " + url,
          SqlStateCode.CLIENT_CONNECTION_FAILED, e);
      }
    }
  }
}

代码示例来源:origin: bwssytems/ha-bridge

public String backup(String aFilename) {
  if(aFilename == null || aFilename.equalsIgnoreCase("")) {
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    aFilename = defaultName + dateFormat.format(Calendar.getInstance().getTime()) + fileExtension; 
  }
  else
    aFilename = aFilename + fileExtension;
  try {
    Files.copy(repositoryPath, FileSystems.getDefault().getPath(repositoryPath.getParent().toString(), aFilename), StandardCopyOption.COPY_ATTRIBUTES);
  } catch (IOException e) {
    log.error("Could not backup to file: " + aFilename + " message: " + e.getMessage(), e);
  }
  log.debug("Backup repository: " + aFilename);
  return aFilename;
}

代码示例来源:origin: bwssytems/ha-bridge

public String restoreBackup(String aFilename) {
  log.debug("Restore backup repository: " + aFilename);
  try {
    Path target = null;
    if(Files.exists(repositoryPath)) {
      DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
      target = FileSystems.getDefault().getPath(repositoryPath.getParent().toString(), defaultName + dateFormat.format(Calendar.getInstance().getTime()) + fileExtension);
      Files.move(repositoryPath, target);
    }
    Files.copy(FileSystems.getDefault().getPath(repositoryPath.getParent().toString(), aFilename), repositoryPath, StandardCopyOption.COPY_ATTRIBUTES);
  } catch (IOException e) {
    log.error("Error restoring the file: " + aFilename + " message: " + e.getMessage(), e);
    return null;
  }
  return aFilename;
}

代码示例来源:origin: apache/hive

@Override
public String validate(String value) {
 final Path path = FileSystems.getDefault().getPath(value);
 if (path == null && value != null) {
  return String.format("Path '%s' provided could not be located.", value);
 }
 final boolean isDir = Files.isDirectory(path);
 final boolean isWritable = Files.isWritable(path);
 if (!isDir) {
  return String.format("Path '%s' provided is not a directory.", value);
 }
 if (!isWritable) {
  return String.format("Path '%s' provided is not writable.", value);
 }
 return null;
}

代码示例来源:origin: btraceio/btrace

static void writeXML(Object obj, String fileName) {
  try {
    Path p = FileSystems.getDefault().getPath(resolveFileName(fileName));
    try (BufferedWriter bw = Files.newBufferedWriter(p, StandardCharsets.UTF_8)) {
      XMLSerializer.write(obj, bw);
    }
  } catch (RuntimeException re) {
    throw re;
  } catch (Exception exp) {
    throw new RuntimeException(exp);
  }
}

代码示例来源:origin: apache/storm

public static String getFileOwner(String path) throws IOException {
  return Files.getOwner(FileSystems.getDefault().getPath(path)).getName();
}

代码示例来源:origin: google/error-prone

@Override
 public void init(JavacTask javacTask, String... args) {
  Iterator<String> itr = Arrays.asList(args).iterator();
  String path = null;
  while (itr.hasNext()) {
   if (itr.next().equals("--out")) {
    path = itr.next();
    break;
   }
  }
  checkArgument(path != null, "No --out specified");

  javacTask.addTaskListener(
    new RefasterRuleCompilerAnalyzer(
      ((BasicJavacTask) javacTask).getContext(), FileSystems.getDefault().getPath(path)));
 }
}

代码示例来源:origin: btraceio/btrace

private static BTraceConfig getConfig() throws IOException {
    FileSystem fs = FileSystems.getDefault();

    Path agentPath = null;
    Path bootPath = null;
    ClassLoader cl = ClassLoader.getSystemClassLoader();
    URL[] urls = ((URLClassLoader)cl).getURLs();
    for (URL url: urls) {
      final String path = url.getPath();
      if (path.contains("btrace-agent")) {
        agentPath = fs.getPath(path);
      } else if (path.contains("btrace-boot")) {
        bootPath = fs.getPath(path);
      }
    }
    if (agentPath == null) { throw new IllegalArgumentException("btrace-agent.jar not found"); }
    if (bootPath == null) { throw new IllegalArgumentException("btrace-boot.jar not found"); }

    Path tmpDir = Files.createTempDirectory("btrace-bench-");

    Path targetPath = Files.copy(agentPath, tmpDir.resolve("btrace-agent.jar"), StandardCopyOption.REPLACE_EXISTING);
    Files.copy(bootPath, tmpDir.resolve("btrace-boot.jar"), StandardCopyOption.REPLACE_EXISTING);

    URL traceLoc = BTraceBench.class.getResource("/scripts/TraceScript.class");
    String trace = traceLoc.getPath();

    return new BTraceConfig(tmpDir, targetPath.toString(), trace);
  }
}

代码示例来源:origin: spotify/helios

public static <T> PersistentAtomicReference<T> create(final Path filename,
                           final JavaType javaType,
                           final Supplier<? extends T> initialValue)
  throws IOException, InterruptedException {
 return new PersistentAtomicReference<>(filename, javaType, initialValue);
}

代码示例来源:origin: apache/hive

private BufferedReader getReaderFor(String filePath) throws HiveException {
 try {
  Path fullFilePath = FileSystems.getDefault().getPath(filePath);
  Path fileName = fullFilePath.getFileName();
  if (Files.exists(fileName)) {
   return Files.newBufferedReader(fileName, Charset.defaultCharset());
  }
  else
  if (Files.exists(fullFilePath)) {
   return Files.newBufferedReader(fullFilePath, Charset.defaultCharset());
  }
  else {
   throw new HiveException("Could not find \"" + fileName + "\" or \"" + fullFilePath + "\" in IN_FILE() UDF.");
  }
 }
 catch(IOException exception) {
  throw new HiveException(exception);
 }
}

代码示例来源:origin: apache/drill

private BufferedReader getReaderFor(String filePath) throws HiveException {
 try {
  Path fullFilePath = FileSystems.getDefault().getPath(filePath);
  Path fileName = fullFilePath.getFileName();
  if (Files.exists(fileName)) {
   return Files.newBufferedReader(fileName, Charset.defaultCharset());
  }
  else
  if (Files.exists(fullFilePath)) {
   return Files.newBufferedReader(fullFilePath, Charset.defaultCharset());
  }
  else {
   throw new HiveException("Could not find \"" + fileName + "\" or \"" + fullFilePath + "\" in IN_FILE() UDF.");
  }
 }
 catch(IOException exception) {
  throw new HiveException(exception);
 }
}

代码示例来源:origin: btraceio/btrace

public static void main(String[] args) throws Exception {
    String path = args[0];

    BTraceProbeFactory bpf = new BTraceProbeFactory(SharedSettings.GLOBAL);

    BTraceProbe bp = bpf.createProbe(new FileInputStream(path));

    FileSystem fs = FileSystems.getDefault();
    Path p = fs.getPath(args[1]);
    Files.write(p.resolve(bp.getClassName().replace(".", "_") + "_full.class"), bp.getFullBytecode());
    Files.write(p.resolve(bp.getClassName().replace(".", "_") + "_dh.class"), bp.getDataHolderBytecode());
  }
}

相关文章