Java文件类String [] list(FilenameFilter fnf)方法,带示例

File Class String []列表(FilenameFilter fnf) (File Class String[] list(FilenameFilter fnf))

  • This method is available in package java.io.File.list(FilenameFilter fnf).

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

  • This method is used to return the names of all the files in the form of an array of strings which is represented in the filepath.

    此方法用于以字符串数组的形式返回所有文件的名称,这些字符串以文件路径表示。

  • The return type of this method is String[] i.e. It returns an array of strings of all the files or directories which is represented in filepath if the given path is directory else return null.

    此方法的返回类型为String [],即,如果给定路径为目录,则返回文件路径中表示的所有文件或目录的字符串数组,否则返回null。

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

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

  • This method is overridable. The first method does not accept any parameter and the second method accept one parameter.

    此方法是可重写的。 第一种方法不接受任何参数,第二种方法则接受一个参数。

Syntax:

句法:

    String[] list(){
}

Parameter(s):

参数:

We pass only one object FilenameFilter as a parameter in the method and with the help of this argument, we can find files with filter(i.e we can find specific files).

我们仅传递一个对象FilenameFilter作为方法中的参数,借助此参数,我们可以找到带有filter的文件(即,可以找到特定的文件)。

Return value:

返回值:

The return type of this method is String[] i.e. it returns all files names in an array of strings which is represented in a filepath.

此方法的返回类型为String [],即它以文件路径表示的字符串数组形式返回所有文件名。

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

// import the File class because we will use File class methods
import java.io.*;
// import the Exception class because it may raise an 
// exception when working with files
import java.lang.Exception;
public class ToListSpecificFiles {
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 file = new File("C:\\Users\\computer clinic\\OneDrive\\Articles");
// Create a FilenameFilter object
FilenameFilter fnf = new FilenameFilter() {
public boolean accept(File file, String name) {
return name.startsWith("J");
}
};
// By using list(fnf) returns all the files and directories 
// which is represented in a file path if file path is a 
// directory and all file or directories starts with 'J'.
String[] filelist = file.list(fnf);
System.out.println("These are the name of files represented in a given directory :" + file.getPath());
// By using loop to traverse the filenames and directories 
// in the given path .
for (int i = 0; i < filelist.length; i++)
System.out.println(filelist[i]);
} catch (Exception e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}

Output

输出量

D:\Programs>javac ToListSpecificFiles.java
D:\Programs>java ToListSpecificFiles
These are the name of files represented in a given directory :C:\Users\computer clinic\OneDrive\Articles
Java File Class canExecute().docx
Java File Class canRead().docx
Java File Class canWrite().docx

翻译自: https://www.includehelp.com/java/file-class-string-list-filenamefilter-fnf-method-with-example.aspx

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

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

相关文章

求最大公因数

while 1:s input(请输入一个数&#xff1a;)e input(请输入一个数&#xff1a;)s int(s)e int(e)if s 0 or e 0:print(错误)continueif s > e:f eelse:f swhile f:if s % f 0 and e % f 0:print(f)breakelse:f f - 1 转载于:https://www.cnblogs.com/wumac/p/567…

窦学计算机基础期末考试,关于新生开学考计算机基础

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼单选题练习1&#xff0e;完整的计算机系统由( c )组成。A&#xff0e;运算器、控制器、存储器、输入设备和输出设备B&#xff0e;主机和外部设备C&#xff0e;硬件系统和软件系统D&#xff0e;主机箱、显示器、键盘、鼠标、打印机…

AIX配置Volumn

我们知道&#xff0c;现在操作系统都具有默认的卷管理系统来管理磁盘。详见存储技术之卷管理和文件系统。总体来说&#xff0c;从下向上分为物理磁盘(PV)、逻辑卷组(VG)、逻辑卷(LV)&#xff0c;用户可以直接mount的是逻辑卷。本文记录一些AIX下的卷管理和配置方法。 AIX下的Vo…

高并发内存占用持续下降_师兄,为什么删除数据后,Redis内存占用依然很高?...

前言上周刚来了个应届小师弟&#xff0c;组长说让我带着&#xff0c;周二问了我这样一个问题&#xff1a;师兄啊&#xff0c;我用top命令看了下服务器的内存占用情况&#xff0c;发现Redis内存占用严重&#xff0c;于是我就删除了大部分不用的keys&#xff0c;为什么内存占用还…

如何打印出给定尺寸的方格_打印给定号码的表格| 8085微处理器

如何打印出给定尺寸的方格Problem statement: 问题陈述&#xff1a; Write an assembly language program in 8085 to print the table of input integer. 在8085中编写汇编语言程序以打印输入整数表。 Assumptions: Suppose the inputted number is at memory location 2050…

maka如何看html文件,自己在MAKA上做得H5,别人如何能看到收集的信息

1。登陆1。 ? ?登陆入口&#xff1a;点击首页右上角“登录”按钮进入登录界面&#xff1b;2。 ? ?登陆界面&#xff1a;输入有效注册的个人账号信息&#xff1a;邮箱、密码&#xff1b;您也可以选择QQ等第三方登录。3。 ? ?密码找回&#xff1a;进入账户登录界面&#xf…

发现保存GIF格式后相素发生变化咋办

数学公式编辑器MathType主要的作用就是编辑公式用的&#xff0c;一些用户朋友编辑完公式希望把公式保存为“高分辨率”的GIF格式&#xff0c;但是在图片查看器中进行浏览查看时发现GIF的分辨率发生了变化&#xff0c;对于这种情况该如何处理呢&#xff1f;下面我们就针对这个问…

3个阶段 项目征名_2020年即将上线的3个爆款,或许它们能改变现有的手游格局...

在近几年国内的手游市场中&#xff0c;基本都被《王者荣耀》和吃鸡类型的给垄断了&#xff0c;偶尔有个别爆款出现&#xff0c;也只是昙花一现&#xff0c;连半年时间都坚持不到&#xff0c;就比如去年的自走棋。不过在2020年&#xff0c;以王者和吃鸡为主的这种格局或许会被打…

python判断素数程序_使用面向对象方法检查素数的Python程序

python判断素数程序This program will check whether a given number is Prime or Not, in this program we will divide the number from 2 to square root of that number, if the number is divided by any number in b/w then the number will not be a prime number. 该程…

湖北计算机技能高考专科学校排名,湖北2021年技能高考专科录取分数线

https://forms.ebdan.net/ls/wg2YPHOQ点击查看全部院校武汉船舶职业技术学院&#xff1a;技能高考(机械类)507技能高考(电气电子类)437技能高考(计算机类)532技能高考(财经类)530技能高考(建筑设计类)319技能高考(旅游类)489技能高考(汽车维修类)466湖北科技职业学院&#xff1…

定位样式

Web页面中的特殊效果&#xff0c;如菜单效果&#xff0c;对话框效果都需要通过定位属性来实现。定位样式position属性可以控制元素的定位类型position属性值可以为sataic、fixed、absolute、relativeposition属性的语法结构- position:value;定位属性static默认值。没有定位&am…

c#异常处理_C#异常处理能力问题和解答 套装2

c#异常处理1) There are the following statements that are given below, which is correct about an exception in C#.NET? The exception occurs at the time of compilationThe exception occurs during program loadingThe exception occurs during JIT compilationThe …

考虑题4所示的日志记录_[南开大学]18秋学期(1703)《数据库基础与应用》在线作业...

18秋学期(1703)《数据库基础与应用》在线作业一、单选题&#xff1a;1.[单选题]在SQL语言中&#xff0c;模式对应于() (满分:)A. 视图和部分基本表B. 基本表C. 存储文件D. 物理磁盘正确答案:——B——2.[单选题]在数据库系统中&#xff0c;读脏数据是指一个事务读了另…

数字图像处理图像反转的实现_反转8位数字| 8085微处理器

数字图像处理图像反转的实现Problem statement: 问题陈述&#xff1a; To reverse 8 bits number using 8085 microprocessors. 使用8085微处理器反转8位数字。 Algorithm: 算法&#xff1a; Load the accumulator with the first data. 向累加器加载第一个数据。 Use RLC i…

计算机控制z反变换公式,第三章 计算机控制系统的数学描述(修正Z变换).ppt

第三章 计算机控制系统的数学描述(修正Z变换)* 3.4 修改Z变换 1&#xff0e;具有多采样频率系统 在某些控制系统中&#xff0c;存在着不同采样频率的采样开关&#xff0c;如图3.10所示。 图3.10 具有不同采样频率系统结构图 图3.10表示&#xff0c;该系统反馈回路的采样频率高一…

7月19日实习日志

今天是实习第十二天&#xff0c;时间过得很快一转眼实习一般都已经过去了&#xff0c;今天早上下了大雨&#xff0c;到单位的时候差一点迟到。 今天难道单位公司的同事就带领着我给公司的防火请升级&#xff0c;防火墙可以是一套硬件或软件&#xff0c;它在网络和互联网之间形成…

g++默认参数_C ++默认参数| 查找输出程序| 套装2

g默认参数Program 1: 程序1&#xff1a; #include <iostream>using namespace std;int K 10;int fun(){return K;}int sum(int X, int Y fun()){return (X Y);}int main(){int A 0;A sum(5);cout << A << " ";K 20;A sum(5);cout <<…

python重载模块_Python 3.0中重载模块

在Python中&#xff0c;每一个以 .py结尾的Python文件都是一个模块。其他的文件可以通过导入一个模块来读取该模块的内容。导入从本质上来讲&#xff0c;就是载入另一个文件&#xff0c;并能够读取那个文件的内容。一个模块的内容通过这样的属性能够被外部世界使用。这种基于模…

计算机考研985院校不歧视,考研最不歧视的985大学有哪些

考研最不歧视的大学有很多&#xff0c;其中985院校有哈尔滨工业大学、对外经济贸易大学、中南大学、河南大学和华东师范大学等。哪些985大学不歧视考研考生1、哈尔滨工业大学面试除了自我介绍&#xff0c;其他都不透露自己的信息&#xff0c;面试老师也都不知道&#xff0c;都是…

如何使用Tornado实现WebSocket服务器?

什么是龙卷风&#xff1f; (What is Tornado?) Tornado is a python web framework and asynchronous networking library. It is scalable and non-blocking. It specializes in dealing with event-driven networking. As tornado supports concurrent connections, natural…