File类boolean isFile() (File Class boolean isFile())

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

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

  • This method is used to check whether the file is specified by filepath is a file 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 file else return false so it is not a file.

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

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

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

Syntax:

句法:

    boolean isFile(){
}

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 then in that case file is specified by abstract file path is a file else returns false so the file is specified is not a file.

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

Java程序演示isFile()方法的示例 (Java program to demonstrate example of isFile() 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 ToCheckFile {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\\myjava.txt");
File file2 = new File("C:\\Users\\computer clinic\\OneDrive\\JavaArticles");
// By using isFile() is used to check whether the filepath
// is a file or not. It returns true because given filepath is a file.
if (file1.isFile())
System.out.println("This filepath " + " " + file1.getAbsolutePath() + " " + "is a file");
else
System.out.println("This filepath " + " " + file1.getAbsolutePath() + " " + "is not a file");
// By using isFile() is used to check whether the filepath
// is a file or not. It returns false because given filepath
// is not a file .
if (file2.isFile())
System.out.println("This filepath " + " " + file2.getAbsolutePath() + " " + "is a file");
else
System.out.println("This filepath " + " " + file2.getAbsolutePath() + " " + "is not a file");
} catch (Exception e) {System.out.println("An error occurred.");
e.printStackTrace();
}
}
}

Output

输出量

D:\Programs>javac ToCheckFile.java
D:\Programs>java ToCheckFile
This filepath  C:\Users\computer clinic\OneDrive\Articles\myjava.txt is a file
This filepath  C:\Users\computer clinic\OneDrive\JavaArticles is not a file

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

Java File类boolean isFile()方法(带示例)相关推荐

  1. Java File类boolean createNewFile()方法(带示例)

    文件类布尔型createNewFile() (File Class boolean createNewFile()) This method is available in package java. ...

  2. Java File类boolean delete()方法(带示例)

    文件类布尔型delete() (File Class boolean delete()) This method is available in package java.io.File.delete ...

  3. createnewfile java_Java File类boolean createNewFile()方法(带示例)

    文件类布尔 createNewFile()软件包java.io.File.createNewFile()中提供了此方法. 此方法用于通过使用createNewFile()方法创建新文件,并且该方法可通 ...

  4. Java File类void deleteOnExit()方法(带示例)

    文件类void deleteOnExit() (File Class void deleteOnExit()) This method is available in package java.io. ...

  5. Java File类静态文件createTempFile(String file_name,String file_extension)方法,带有示例...

    File类静态文件createTempFile(String file_name,String file_extension) (File Class static File createTempFi ...

  6. java file用法_Java File 类的使用方法详解(转)

    转自:http://www.codeceo.com/article/java-file-class.html Java File类的功能非常强大,利用Java基本上可以对文件进行所有的操作.本文将对J ...

  7. java.io.File.setExecutable(boolean executable) 方法来设置所有者对于此抽象路径名执行权限。

    java.io.File.setExecutable(boolean executable) 方法来设置所有者对于此抽象路径名执行权限. 声明 以下是 java.io.File.setExecutab ...

  8. java.util.zip 用法,Java压缩文件工具类ZipUtil使用方法代码示例

    本文实例通过Java的Zip输入输出流实现压缩和解压文件,前一部分代码实现获取文件路径,压缩文件名的更改等,具体如下: package com.utility.zip; import java.io. ...

  9. JAVA File类、IO流体验与简介(字节流、字符流、序列流、打印流、编码、递归)

    1. File类 1.1. File类说明 存储在变量,数组和对象中的数据是暂时的,当程序终止时他们就会丢失.为了能够永 久的保存程序中创建的数据,需要将他们存储到硬盘或光盘的文件中.这些文件可以移动 ...

最新文章

  1. Windows Phone 几种页面间传递数据的方式
  2. 土壤微生态文献包免费领取 | 150篇近两年高影响因子土壤微生态相关文章
  3. oral_quiz-#求链表中的倒数第K个结点#
  4. 中兴智能视觉大数据公交车专用道移动智能电子警察系统功能、特点及优势详细介绍...
  5. Android构建boot.img(二):kernel的拷贝与打包
  6. 7-3 最小生成树-kruskal (10 分)(思路+详解+并查集详解+段错误超时解决)宝 Come
  7. dubbo源码解析(一)
  8. 这本京东断货王的Python神书,刷爆整个编程圈!| 测评
  9. 从零实现深度学习框架——深入浅出交叉熵
  10. linux v4l2进行视频采集编程介绍
  11. linux查找文件夹命令
  12. MindManager 2020下载与使用
  13. 计算机博士差国际期刊能申请答辩吗,博士生申请答辩注意事项
  14. 1.7.3_NandFlash的芯片id读取_P
  15. 无线移动通信技术快速发展历程和趋向
  16. HDOJ 6078-Wavel Sequence
  17. K8s Liveness/Readiness/Startup 探针机制
  18. 数据库系统概论----关系运算之除运算
  19. 符号“∑”和“Π”的用法。
  20. LNMP 架构部署(附:部署 Discuz 社区论坛 Web 应用)

热门文章

  1. latex 算法_GitHub项目awesome-latex-drawing新增内容(四):绘制贝叶斯网络
  2. php 安全mysql,关于php:我从mysql注入安全吗?
  3. java多台_Java 多态
  4. oracle迁移undo表空间,oracle切换undo表空间
  5. java emoji显示乱码_Java 解决Emoji表情过滤问题
  6. shell 生活0806012145
  7. 形象易懂讲解算法I——小波变换
  8. JVM(三)——对象的访问定位
  9. TODO:macOS上ThinkPHP5和Semantic-UI集成
  10. 微信小程序简单入门1