File类 、FileFilter过滤、Properties

1、File路径分隔符、文件名称分隔符
在这里插入图片描述
2、路径
在这里插入图片描述
3、File文件的遍历
在这里插入图片描述
4、FilrFilter过滤器
在这里插入图片描述
在这里插入图片描述
5、Properties

package com.hu.yan;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;

/**
 * Properties是唯一一个IO流有关的集合
 * 
 * Properties集合是一个双列集合,key和value默认都是字符串
 *
 */
public class PropertiesTest {
   
	public static void main(String[] args) throws Exception {
		showo1();
		show02();
		show03();
	}
    
	private static void show03() throws Exception, IOException {
		Properties properties = new Properties();
		properties.load(new FileReader("文件地址"));
		Set<String> set = properties.stringPropertyNames();
		for(String key : set) {
			String value = (String) properties.get(key);
			System.out.println(value);
		}
	}

	private static void show02() throws IOException {
		Properties properties = new Properties();
		properties.setProperty("张三", "168");
		properties.setProperty("张三2", "168");
		properties.setProperty("张三3", "168");
		FileWriter fw = new FileWriter("写入到哪儿的地址");
		properties.store(fw,"save data");
		fw.close();
		//字节流不可写中文乱码 字符流可以
		properties.store(new FileOutputStream("文件名字"), "");
		
	}

	//使用Properties集合存储数据,遍历取出Properties集合中的数据
	private static void showo1() {
	 //创建一个Properties集合对象
		Properties properties = new Properties();
		properties.setProperty("张三", "168");
		properties.setProperty("张三2", "168");
		properties.setProperty("张三3", "168");
		
	//取出集合中的键
		Set<String> set = properties.stringPropertyNames();
		for(String key : set) {
			String value = properties.getProperty(key);
			System.out.println(value);
		}
	}
}

待更新

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
FileFilter是一个接口,用于过滤文件。具体来说,FileFilter有一个方法accept,用于判断某个文件是否符合过滤条件。如果accept方法返回true,则表示该文件符合过滤条件;如果返回false,则表示该文件不符合过滤条件。 在使用FileFilter时,可以自定义实现来重写accept方法,并在方法中定义过滤的规则。例如,可以使用Lambda表达式来实现FileFilter接口,并重写accept方法,以实现自定义的过滤规则。如引用所示,可以通过Lambda表达式实现过滤以".txt"结尾的文件。 另外,还可以使用递归的方式访问指定路径下的所有文件,并根据过滤规则进行过滤。如引用所示,通过递归访问桌面上的所有以".txt"结尾的文件,可以实现获取所有符合过滤条件的文件。 总而言之,FileFilter是一个接口,用于过滤文件。可以通过自定义实现或使用Lambda表达式来实现FileFilter接口,并根据需要定义过滤规则,以筛选出符合条件的文件。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [【java笔记】File(3):FileFilter文件过滤器原理和使用](https://blog.csdn.net/m0_52043808/article/details/123258066)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值