本文整理汇总了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;
}
示例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);
}
}
示例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();
}
示例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.");
}
}
示例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);
}
}
}
}
}
}
}
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
示例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();
}
示例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) + ")";
}
};
}
示例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);
}
}
示例14: isDirectoryExists
import java.nio.file.Files; //导入方法依赖的package包/类
public static boolean isDirectoryExists(String directory) {
return Files.isDirectory(new File(directory).toPath());
}
示例15: isDirectory
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public boolean isDirectory() {
return Files.isDirectory(path);
}