毕向东_Java基础视频教程第20天_IO流(5~6)
第20天-05-IO流(文件列表一)
static File[] listRoots()
List the available filesystem roots.
String[] list()
Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.
String[] list(FilenameFilter filter)
Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
File[] listFiles()
Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.
File[] listFiles(FileFilter filter)
Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
File[] listFiles(FilenameFilter filter)
Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
package bxd;
import java.io.File;
public class FileDemo4 {
public static void method_1() {
File[] files = File.listRoots();
for (File file : files) {
System.out.println(file);
}
}
public static void method_2() {
File dir = new File("/Users/Eric/Desktop");
// 如果File dir传入的不是目录而是文件, 则会抛出空指针异常
for (String name : dir.list()) {
System.out.println(name);
}
}
public static void main(String[] args) {
method_2();
}
}
第20天-06-IO流(文件列表二)
package bxd; import java.io.File;
import java.io.FilenameFilter; public class FileDemo5 {
public static void method_1() {
File demoDir = new File("/Users/Eric/Desktop");
String[] names = demoDir.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) { // accept方法的入参File dir即为File demoDir
return name.endsWith(".pdf");
}
}); for (String name : names) {
System.out.println(name);
}
} public static void method_2() {
File dir = new File("/Users/Eric/Desktop");
for (File file : dir.listFiles()) {
System.out.println(file.getName() + "::" + file.length());
}
} public static void main(String[] args) {
method_2();
}
}
毕向东_Java基础视频教程第20天_IO流(5~6)的更多相关文章
- 毕向东_Java基础视频教程第20天_IO流(7~10)
第20天-07-IO流(递归) package bxd; import java.io.File; public class FileDemo3 { // 非递归打印 public static vo ...
- 毕向东_Java基础视频教程第20天_IO流(15~17)
第20天-15-IO流(打印输出流) 打印输出流:PrintWriter与PrintStream 两者的区别:Since JDK 1.4 it's possible to specify the ch ...
- 毕向东_Java基础视频教程第20天_IO流(11~14)
第20天-11-IO流(Properties简述) .properties是一种主要在Java相关技术中用来存储应用程序的可配置参数的文件的文件扩展名.它们也可以存储用于国际化和本地化的字符串,这种文 ...
- 毕向东_Java基础视频教程第20天_IO流(1~4)
第20天-01-IO流(File概述) File类: 用来将文件或者文件夹封装成对象, 方便进行操作. File对象可以作为参数, 传递给流对象的构造函数. 流对象不能操作文件夹; 流对象不能操作文件 ...
- 毕向东_Java基础视频教程第19天_IO流(20~22)
第19天-20-IO流(改变标准输入输出设备) static void setIn(InputStream in) Reassigns the "standard" input s ...
- 毕向东_Java基础视频教程第19天_IO流(01~05)
第19天-01-IO流(BufferedWriter) 字符流的缓冲区 缓冲区的出现提高了对数据的读写效率. 对应类缓冲区要结合流才可以使用. BufferedWriter BufferedReade ...
- 毕向东_Java基础视频教程第19天_IO流(06~10)
第19天-06-IO流(装饰设计模式) 装饰设计模式: 当想要对已有的对象进行功能增强时, 可以定义类,将已有对象传入,基于已有的功能,并提供加强功能.那么这个自定义的类称为装饰类. 装饰类通常会通过 ...
- 毕向东_Java基础视频教程第19天_IO流(11~14)
第19天-11-IO流(字节流File读写操作) import java.io.FileInputStream; import java.io.FileOutputStream; import jav ...
- 毕向东_Java基础视频教程第21天_IO流(1)
第21天-01-IO流(对象的序列化) ObjectInputStream与ObjectOutputStream 被操作的对象需要实现Serializable接口(标记接口) 非必须, 但强烈建议所有 ...
随机推荐
- C基础《一》
puts("第一个C语言程序输出了") C语言的编译和链接过程 C语言写的代码必须经过编译生成可执行文件才可以用, 编译就是把C语言写的代码进行识别,转换成计算机能够识别的二进制形 ...
- maven工程下testng简单使用
创建maven工程后,将Repository仓库中maven代码粘贴复制到pom.xml文件中,仓库地址:<!-- https://mvnrepository.com/artifact/org. ...
- CentOS 7 主机名bogon解决办法
转https://blog.csdn.net/qq_24221531/article/details/80334942 一.修改linux主机的配置文件/etc/hostname 和 /etc/hos ...
- Struts2方法调用的三种方式(有新的!调用方法的说明)
在Struts2中方法调用概括起来主要有三种形式 第一种方式:指定method属性 <action name="heroAction" class="com.ABC ...
- 创建自己的区块链游戏SLOT——以太坊代币(三)
一个以太坊合约版本的轮盘游戏,向合约转账ETH,有几率获得3,5,10,100倍奖励 合约地址:0x53DA598E70a1505Ad95cBF17fc5DCA0d2c51174b 捐赠ETH地址:0 ...
- 从setTimeout谈js运行机制
众所周知,JavaScript是单线程的编程,什么是单线程,就是说同一时间JavaScript只能执行一段代码,如果这段代码要执行很长时间,那么之后的代码只能尽情地等待它执行完才能有机会执行,不像人一 ...
- python笔记02-----字符串操作
python中定义变量的字符串 str1 = "www" #str1就是字符串了 一定用引号 或者直接使用"字符串."来调用内部的方法 1.字符串大小 ...
- SpringMVC内置的精准数据绑定2
https://blog.csdn.net/flashflight/article/details/42935137 之前写过一篇<扩展SpringMVC以支持更精准的数据绑定1>用于完成 ...
- slot的使用
1.slot https://www.w3cplus.com/vue/vue-slot.html 2.ref https://www.cnblogs.com/xumqfaith/p/7743387.h ...
- kinect 深度图像去噪算法
算法设计思路 (1)读取16位深度图像到待处理图像帧组: (2)ROI区域计算 由于kinect 彩色摄像头和红外深度摄像头是存在视角偏差的,经过视角对齐后,得到的深度图像是有黑边的.此处通过取帧组第 ...