Java文件类boolean isDirectory()方法(带示例)

文件类boolean isDirectory() (File Class boolean isDirectory())

  • This method is available in package java.io.File.isDirectory().

    软件包java.io.File.isDirectory()中提供了此方法。

  • This method is used to check whether the file is specified by filepath is a directory or not.

    此方法用于检查filepath指定的文件是否为目录。

  • The return type of this method is Boolean i.e. The value of this method is true or false if it returns true that means the file is represented by filepath is a directory else return false so it is not a directory.

    此方法的返回类型为布尔值,即,如果该方法返回true,则该值为true或false,这意味着该文件由filepath表示为目录,否则返回false,因此它不是目录。

  • This method may raise an exception(i.e. Security Exception) if the read access is not given to the file.

    如果未授予文件读取权限,则此方法可能会引发异常(即Security Exception)。

Syntax:

句法:

    boolean isDirectory(){
}

Parameter(s):

参数:

We don’t pass any object as a parameter in the method of the File.

我们不会在File方法中将任何对象作为参数传递。

Return value:

返回值:

The return type of this method is Boolean i.e. it returns true than in that case file is specified by abstract file path is a directory else returns false so the file is specified is not in a directory.

此方法的返回类型为Boolean,即,与在那种情况下文件由抽象文件路径指定为目录的情况下返回true,否则返回false,因此指定的文件不在目录中。

Java程序演示isDirectory()方法的示例 (Java program to demonstrate example of isDirectory() method)

// import the File class because we will use File class methods
import java.io.File;
// import the Exception class because it may raise 
// an exception when working with files
import java.lang.Exception;
public class ToCheckFileDirectory {
public static void main(String[] args) {
try {
// Specify the path of file and we use double slashes 
// to escape '\' character sequence for windows otherwise 
// it will be considerable as url.
File file1 = new File("C:\\Users\\computer clinic\\OneDrive\\Articles");
File file2 = new File("C:\\Users\\computer clinic\\OneDrive\\JavaArticles");
// By using isDirectory() is used to check whether 
// the filepath is a directory or not. 
// It returns true because given filepath is a directory .
if (file1.isDirectory())
System.out.println("This filepath " + " " + file1.getAbsolutePath() + " " + "is a directory");
else
System.out.println("This filepath " + " " + file1.getAbsolutePath() + " " + "is not a directory");
// By using isDirectory() is used to check whether 
// the filepath is a directory or not. It returns false 
// because given filepath is not a directory .
if (file2.isDirectory())
System.out.println("This filepath " + " " + file2.getAbsolutePath() + " " + "is a directory ");
else
System.out.println("This filepath " + " " + file2.getAbsolutePath() + " " + "is not a directory");
} catch (Exception e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}

Output

输出量

D:\Programs>javac ToCheckFileDirectory.java
D:\Programs>java ToCheckFileDirectory
This filepath C:\Users\computer clinic\OneDrive\Articles is a directory
This filepath C:\Users\computer clinic\OneDrive\JavaArticles is not a directory

翻译自: https://www.includehelp.com/java/file-class-boolean-isdirectory-method-with-example.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542299.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

微信小程序简单入门1

参考文档:https://mp.weixin.qq.com/debug/wxadoc/dev/index.html1 创建项目开发者工具安装完成后,打开并使用微信扫码登录。选择创建“项目”,填入上文获取到的 AppID ,(无appid直接选择)设置一个本地项目…

leetcode数组汇总_LeetCode刷题实战118:杨辉三角

算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试算法面试。所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就从LeetCode上面选 !今天和大家…

位运算使奇数+1 偶数-1_C ++程序打印从1到N的所有偶数和奇数

位运算使奇数1 偶数-1Problem: Take input from the user (N) and print all EVEN and ODD numbers between 1 to N. 问题:从用户那里输入(N),并打印1至N之间的所有偶数和奇数编号。 Solution: 解: Input an integer number (N). 输入一个整…

javascript 模块化机制

1. 概述 js发展初期暴露了其缺陷:缺乏模块,后来提出了commonJS规范来规范其模块的规范。作为JavaScript新手,发现对于其JavaScript的模块机制,不是很理解。我查阅了一些资料整理了JavaScript CommonJS的原理和机制。 2. JavaScrip…

c语言 宏定义 去除宏定义_如何检查是否在C中定义了宏?

c语言 宏定义 去除宏定义To check whether a Macro is defined or not in C language – we use #ifdef preprocessor directive, it is used to check Macros only. 要检查是否用C语言定义了宏 -我们使用#ifdef预处理程序指令,它仅用于检查宏。 Syntax: 句法&…

多线程下不能用truncate吗_那么多的化妆品,怀孕后都不能用了吗?

前几天圆梦参加了青岛的美博会,里面的化妆品真多啊,无论是护肤、美白、彩妆比比皆是,看的人眼(liu)花(lian)缭(wang)乱(fan)。虽说国务院宣布的新…

手机html5性能测试工具,HTML5模块 性能方面8大测试环节_小米 M3_手机硬件频道-中关村在线...

Vellamo作为一款专攻网页浏览性能测试的工具,在这方面的测试环节也相对复杂很多。这一部分在Vellamo的HTML5测试环节中通过14项测试来进行体现,而接下来我们会对着实际个测试项进行相应的介绍。See The Sun Canvas/Pixel Blender测试界面See The Sun Can…

[计算机网络]httpserver--如何解析HTTP请求报文

这个http server的实现源代码我放在了我的github上,有兴趣的话可以点击查看哦。 在上一篇文章中,讲述了如何编写一个最简单的server,但该程序只是接受到请求之后马上返回响应,实在不能更简单。在正常的开发中,应该根据…

python字典副本_如何复制字典并仅在Python中编辑副本?

python字典副本Python never implicitly copies the dictionary or any objects. So, while we set dict2 dict1, were making them refer to the same dictionary object. Hence, even when we mutate the dictionary, all the references made to it, keep referring to the…

英特尔核芯显卡控制面板没有了_核显和独显、集成显卡有什么区别

集成显卡:一般不带有显存,而是使用系统的一部分主内bai存作为显存,具体的数量一般是系统根据需要自动动态调整的。显然,如果使用集成显卡运行需要大量占用内存的空间,对整个系统的影响会比较明显,此外系统内…

徐州初中计算机学校排名2015,徐州初中学校排名,徐州重点初中排名详细榜单

2018年徐州初中学校排名,徐州重点初中排名详细榜单孩子小升初,几乎所有的家长都会陷入纠结,都想为孩子选择一所“好学校”,在择校过程中,家长们总想知道徐州初中学校排名以及徐州重点初中排名详细榜单,但这里小编提醒一…

分布式计算 MapReduce与yarn工作机制

一、第一代hadoop组成与结构第一代Hadoop,由分布式存储系统HDFS和分布式计算框架MapReduce组成,其中,HDFS由一个NameNode和多个DataNode组成,MapReduce由一个JobTracker和多个TaskTracker组成,对应Hadoop版本为Hadoop …

c++ stl队列初始化_创建一个向量,并将其像C ++ STL中的数组一样初始化

c stl队列初始化向量是什么? (What is the vector?) Vector is a container in C STL, it is used to represent array and its size can be changed. Vector是C STL中的一个容器,用于表示数组,并且其大小可以更改。 Read more: C STL Vec…

计算机无法上无线网络连接到internet,电脑连接不上无线网络,教您怎么解决电脑连接不上无线网络...

小编家的那位笔记本姐姐之前可能是受委屈了,一个一个的电脑问题丢出来给我解决。之前有段时间总是出现电脑连接不上无线网络的问题,弄得那短时间天天都在想办法是解决。现在,我就要将这种解决方法分享给你们,让你们在遇到这个问题…

格兰杰因果关系检验_混频(mixed frequency)数据的格兰杰因果(Grange causality)检验及其Matlab实现...

格兰杰和格兰杰因果网络搜到的Grange大神标准照格兰杰1934年9月出生于英国威尔士的斯旺西,早期就读于诺丁汉大学,接受当时英国第一个经济学数学双学位教育,1955年留校任教,1957年在天文学杂志上他发表了第一篇论文:“关…

C#Convert.ToInt32(byte)方法-将字节值转换为int

C#Convert.ToInt32(byte)方法 (C# Convert.ToInt32(byte) Method) Convert.ToInt32(byte) Method is used to convert a specific byte value to its equivalent integer (int 32 signed number). Convert.ToInt32(byte)方法用于将特定的字节值转换为其等效的整数(i…

后台窗口截图_万人拥捧的截图软件来啦!让你的工作效率提升不止一倍!

文章来自微信公众号:小七有料直接进入正题,今天不野给大家分享两款截图软件——Snipaste和FastStone Capture,前者与其说是一个截图软件,我更愿意称之为贴图软件。两者都在工作中很大程度提高了我的效率,也简便化了我很…

ibm nvidia 超级计算机,IBM,Nvidia和美国能源部组成一个超级计算机超级团队

CNET技术信息网7月15日国际报道: IBM将与Nvidia和美国能源部合作建立两个新的杰出超级计算机中心. 这项合作的工作主要集中在两个方面,一个是确保应用程序可以充分利用超级计算机的强大性能,另一个是收集开发人员,工程师和科学家的反馈.这两个…

C#Convert.ToInt32(char)方法-将char值转换为int

C#Convert.ToInt32(char)方法 (C# Convert.ToInt32(char) Method) Convert.ToInt32(char) Method is used to convert a specific char value to its equivalent integer (int 32 signed number) (It can also be known as ASCII value). Convert.ToInt32(char)方法…

华为p40论坛_华为高端旗舰继续发力!麒麟990 5G+超感知三摄,256GB降价799元

小米10、一加8,vivo NEX3S等高性能旗舰产品现已在市场上发售。其中,5G旗舰华为P40也在销售团队中,并且最近成为最受欢迎的旗舰产品。由于华为P40高端版从799元跌至4189元,消费者可以以不到800元的价格购买低价高性能旗舰产品&…