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


Java Files.isDirectory方法代碼示例

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


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

示例1: hasNext

import java.nio.file.Files; //導入方法依賴的package包/類
@Override
public boolean hasNext() {
    if (next != null)
        return true;

    while (next == null) {
        if (pathIter.hasNext()) {
            Path path = pathIter.next();
            if (Files.isDirectory(path)) {
                next = scanDirectory(path);
            } else {
                next = scanFile(path);
            }
            pathIndex++;
        } else
            return false;
    }
    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:Locations.java

示例2: createObject

import java.nio.file.Files; //導入方法依賴的package包/類
void createObject(Path path, boolean isRoot) {
    if (isRoot) {
        TreeItem<Path> rootNode = setRootItem(path);
        treeView.setRoot(rootNode);
    } else {
        TreeItem<Path> parent = getItem(treeView.getRoot(), path.getParent());

        WatcherStructure watcherStructure = null;
        if (Files.isDirectory(path)) {
            watcherStructure = new WatcherStructure(path, project, tabUpdater, this);
        }

        TreeItem<Path> newItem = new CustomTreeItem(path, watcherStructure, project, tabUpdater, this);
        CustomIcons customIcons = new CustomIcons();
        if (Files.isDirectory(path)) {
            newItem.setGraphic(new ImageView(customIcons.getFolderCollapseImage()));
            newItem.expandedProperty().addListener(expanderListener());
        } else {
            newItem.setGraphic(new ImageView(customIcons.getFileImage()));
        }

        parent.getChildren().add(newItem);

        sortItemsInTree(parent);
    }
}
 
開發者ID:MrChebik,項目名稱:Coconut-IDE,代碼行數:27,代碼來源:TreeUpdater.java

示例3: getPermissions

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Returns formatted permissions for current file.
 * @param path Current file.
 * @return Formatted permissions.
 */
private String getPermissions(Path path) {
	char directory = '-';
	if (Files.isDirectory(path))
		directory = 'd';

	char readable = '-';
	if (Files.isReadable(path))
		readable = 'r';

	char writeable = '-';
	if (Files.isWritable(path))
		writeable = 'w';

	char executable = '-';
	if (Files.isExecutable(path))
		executable = 'x';

	return new StringBuilder().append(directory).append(readable)
			.append(writeable).append(executable).toString();
}
 
開發者ID:fgulan,項目名稱:java-course,代碼行數:26,代碼來源:LsShellCommand.java

示例4: execute

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * execute.
 * @param cmd - cmd
 * @throws IOException - IOException
 */
@Override
public void execute(Command cmd) throws IOException {
    Path filePath = Paths.get(cmd.getParam());
    if (Files.exists(filePath, LinkOption.NOFOLLOW_LINKS)
            && !Files.isDirectory(filePath) && Files.isReadable(filePath)) {

        System.out.println("Uploading...");

        ObjectOutputStream oos = new ObjectOutputStream(outputStream);
        oos.writeObject(cmd);
        oos.flush();

        WritableByteChannel rbc = Channels.newChannel(new DataOutputStream(outputStream));
        FileInputStream fis = new FileInputStream(cmd.getParam());
        fis.getChannel().transferTo(0, Long.MAX_VALUE, rbc);
        rbc.close();

        System.out.println("Done.");
    } else {
        System.out.println("Error. Please try again.");
    }
}
 
開發者ID:istolbov,項目名稱:i_stolbov,代碼行數:28,代碼來源:CommandFactoryClient.java

示例5: scanAndLoadDictionaries

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Scans the hunspell directory and loads all found dictionaries
 */
private void scanAndLoadDictionaries() throws IOException {
    if (Files.isDirectory(hunspellDir)) {
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(hunspellDir)) {
            for (Path file : stream) {
                if (Files.isDirectory(file)) {
                    try (DirectoryStream<Path> inner = Files.newDirectoryStream(hunspellDir.resolve(file), "*.dic")) {
                        if (inner.iterator().hasNext()) { // just making sure it's indeed a dictionary dir
                            try {
                                dictionaries.getUnchecked(file.getFileName().toString());
                            } catch (UncheckedExecutionException e) {
                                // The cache loader throws unchecked exception (see #loadDictionary()),
                                // here we simply report the exception and continue loading the dictionaries
                                logger.error("exception while loading dictionary {}", file.getFileName(), e);
                            }
                        }
                    }
                }
            }
        }
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:25,代碼來源:HunspellService.java

示例6: getRecipesFolder

import java.nio.file.Files; //導入方法依賴的package包/類
private File getRecipesFolder() {

		Path recipesDir = Paths.get(System.getProperty("user.home"), ".recipes");

		try {
			if (!Files.isDirectory(recipesDir))
				Files.createDirectory(recipesDir);
		} catch (IOException e) {
			logger.error(e.getMessage());
			e.printStackTrace();
			return null;
		}

		return recipesDir.toFile();
	}
 
開發者ID:NMSU-SIC-Club,項目名稱:JavaFX_Tutorial,代碼行數:16,代碼來源:RecipeLoaderService.java

示例7: main

import java.nio.file.Files; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException
{
   Scanner input = new Scanner(System.in);

   System.out.println("Enter file or directory name:");

   // create Path object based on user input
   Path path = Paths.get(input.nextLine());

   if (Files.exists(path)) // if path exists, output info about it
   {
      // display file (or directory) information
   	System.out.printf("%n%s exists%n", path.getFileName());
   	System.out.printf("%s a directory%n", 
   		Files.isDirectory(path) ? "Is" : "Is not");
   	System.out.printf("%s an absolute path%n", 
   		path.isAbsolute() ? "Is" : "Is not");
   	System.out.printf("Last modified: %s%n", 
   		Files.getLastModifiedTime(path));
   	System.out.printf("Size: %s%n", Files.size(path));
   	System.out.printf("Path: %s%n", path);
   	System.out.printf("Absolute path: %s%n", path.toAbsolutePath());

      if (Files.isDirectory(path)) // output directory listing
      {
         System.out.printf("%nDirectory contents:%n");
         
         // object for iterating through a directory's contents
         DirectoryStream<Path> directoryStream = 
            Files.newDirectoryStream(path);

         for (Path p : directoryStream)
            System.out.println(p);
      } 
   } 
   else // not file or directory, output error message
   {
      System.out.printf("%s does not exist%n", path);
   }   
}
 
開發者ID:cleitonferreira,項目名稱:LivroJavaComoProgramar10Edicao,代碼行數:41,代碼來源:FileAndDirectoryInfo.java

示例8: newModuleInfoSupplier

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Returns a supplier of an input stream to the module-info.class
 * on the class path of directories and JAR files.
 */
Supplier<InputStream> newModuleInfoSupplier() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    for (Path e: classpath) {
        if (Files.isDirectory(e)) {
            Path mi = e.resolve(MODULE_INFO);
            if (Files.isRegularFile(mi)) {
                Files.copy(mi, baos);
                break;
            }
        } else if (Files.isRegularFile(e) && e.toString().endsWith(".jar")) {
            try (JarFile jf = new JarFile(e.toFile())) {
                ZipEntry entry = jf.getEntry(MODULE_INFO);
                if (entry != null) {
                    jf.getInputStream(entry).transferTo(baos);
                    break;
                }
            } catch (ZipException x) {
                // Skip. Do nothing. No packages will be added.
            }
        }
    }
    if (baos.size() == 0) {
        return null;
    } else {
        byte[] bytes = baos.toByteArray();
        return () -> new ByteArrayInputStream(bytes);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:33,代碼來源:JmodTask.java

示例9: collectClassFiles

import java.nio.file.Files; //導入方法依賴的package包/類
private void collectClassFiles(Path dir, List<String> result) {
  if (Files.exists(dir)) {
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
      for (Path entry: stream) {
        if (Files.isDirectory(entry)) {
          collectClassFiles(entry, result);
        } else {
          result.add(entry.toString());
        }
      }
    } catch (IOException x) {
      throw new AssertionError(x);
    }
  }
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:16,代碼來源:D8IncrementalRunExamplesAndroidOTest.java

示例10: SaveFile

import java.nio.file.Files; //導入方法依賴的package包/類
private void SaveFile(String fName, IniFile data) {
    try {
        String wdata = "";
        Object[] adata = data.data.keySet().toArray();
        Object[] akdata;
        Object[] avdata;

        for (int i = 0; i < adata.length; i++) {
            if (i > 0) {
                wdata += "\r\n";
            }

            if (!((String) adata[i]).equals("")) {
                wdata += "[" + ((String) adata[i]) + "]\r\n";
            }

            akdata = data.data.get(((String) adata[i])).keySet().toArray();
            avdata = data.data.get(((String) adata[i])).values().toArray();

            for (int b = 0; b < akdata.length; b++) {
                wdata += ((String) akdata[b]) + "=" + ((String) avdata[b]) + "\r\n";
            }
        }
        if (!Files.isDirectory(Paths.get("./" + inifolder + "/"))) {
            Files.createDirectory(Paths.get("./" + inifolder + "/"));
        }

        Files.write(Paths.get("./" + inifolder + "/" + fName + ".ini"), wdata.getBytes(StandardCharsets.UTF_8),
                StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);

        changed.remove(fName);
    } catch (IOException ex) {
        com.gmt2001.Console.err.printStackTrace(ex);
    }
}
 
開發者ID:GloriousEggroll,項目名稱:quorrabot,代碼行數:36,代碼來源:IniStore.java

示例11: findTestDir

import java.nio.file.Files; //導入方法依賴的package包/類
String findTestDir(String dir) throws IOException {
    Path path = Paths.get(dir).toAbsolutePath();
    while (path != null && !path.endsWith("test")) {
        path = path.getParent();
    }
    if (path == null) {
        throw new IllegalArgumentException(dir + " is not in a test directory");
    }
    if (!Files.isDirectory(path)) {
        throw new IOException(path.toString() + " is not a directory");
    }
    return path.toString();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:CreateMultiReleaseTestJars.java

示例12: isDirectory

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Returns a predicate that returns the result of {@link Files#isDirectory(Path, LinkOption...)}
 * on input paths with the given link options.
 */
public static Predicate<Path> isDirectory(LinkOption... options) {
  final LinkOption[] optionsCopy = options.clone();
  return new Predicate<Path>() {
    @Override
    public boolean apply(Path input) {
      return Files.isDirectory(input, optionsCopy);
    }

    @Override
    public String toString() {
      return "MoreFiles.isDirectory(" + Arrays.toString(optionsCopy) + ")";
    }
  };
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:19,代碼來源:MoreFiles.java

示例13: deleteFolder

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Deletes the given folder.
 * 
 * @param folder
 * @should delete folder correctly
 */
protected static void deleteFolder(Path folder) {
    if (!Files.isDirectory(folder)) {
        logger.debug("File '{}' is not a directory.", folder.toAbsolutePath());
        return;
    }
    try {
        FileUtils.deleteDirectory(folder.toFile());
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
}
 
開發者ID:intranda,項目名稱:goobi-viewer-indexer,代碼行數:18,代碼來源:DataRepository.java

示例14: isDirectoryExists

import java.nio.file.Files; //導入方法依賴的package包/類
public static boolean isDirectoryExists(String directory) {
  return Files.isDirectory(new File(directory).toPath());
}
 
開發者ID:DSC-SPIDAL,項目名稱:twister2,代碼行數:4,代碼來源:FileUtils.java

示例15: isDirectory

import java.nio.file.Files; //導入方法依賴的package包/類
@Override
public boolean isDirectory() {
    return Files.isDirectory(path);
}
 
開發者ID:PizzaCrust,項目名稱:Passion,代碼行數:5,代碼來源:PathEnvFile.java


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