File(二) Properties
来源:互联网 发布:广州数控编程代码大全 编辑:程序博客网 时间:2024/06/05 02:16
递归方法的使用:
使用递归的方法列出从多级目录下面所有的文件:
public class Demo13 { public static void main(String[] args) { File file = new File("D:\\LQBZ"); showFile(file); } public static void showFile(File dir) { File[] filelist = dir.listFiles(); for (File eachFile : filelist) { if (eachFile.isDirectory()) { System.out.println(eachFile.getName() + "==============="); showFile(eachFile); } else { System.out.println(eachFile.getName()); } } }}
个人感觉:使用递归最重要的是
1.判断的条件(也就是在什么情况下调用自己)
2.对条件的处理(不能让他无限制不做任何更改的一直调用自己,会死循环)
3.注意递归的资料,避免内存溢出
递归分为有返回值递归和无返回值递归
无返回值递归 一般用于当时就可以对数据或文件进行处理操作
有返回值递归 一般用于需要依靠下面递归返回的值,然后对本身进行处理。
使用递归删除带内容的目录:
public static void removeFile(File dir) {File[] fileList = dir.listFiles();for (File file : fileList) {
// 判断文件不是隐藏的,并且是目录
if (!file.isHidden()&&file.isDirectory()) { removeFile(file);} else {file.delete();}}dir.delete();}
Properties对象
设置元素
Properties p = new Properties();
p.setProperty("zhangsan", "20");
获取元素
p.getProperty("zhangsan");
将propertity转换为Set<String> 方便遍历
将文档中的数据放到Propertity中
try {Properties p = new Properties();Reader read = new FileReader("D:\\aa.txt");BufferedReader bd = new BufferedReader(read);String len = "";while ((len = bd.readLine()) != null) {String[] info = len.split("=");p.setProperty(info[0], info[1]);}} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}
直接加载字符流到Properties
FileInputStream fis = new FileInputStream("D:\\aa.txt");
p.load(fis);
将Properties信息保存到一个文件
p.store(fos, "这里是每行的注释");
- File(二) Properties
- IO流(二)之File,递归,Properties详解
- Read .properties file
- 写properties file 例子
- Use properties file
- Sample log4j.properties file
- File、Properties、printWiriter
- JAVA之旅(二十九)——文件递归,File结束练习,Properties,Properties存取配置文件,load,Properties的小练习
- 黑马程序员--IO(二)-File类、Properties类、打印流、序列流(合并流)
- JAVA基础学习(二十一)--IO流三-File、Properties、PrintWriter与合并、分割流
- 黑马程序员--IO(二)--File类、Properties类、打印流、序列流等
- Java I/O流(二)——File,Properties,PrintWriter,IO ,RandomAccessFile,ByteBuffer,nio
- Get a file's properties
- IO(File、递归、Properties)
- 黑马程序员17.File&Properties
- 黑马程序员 File&Properties&URL
- File类与Properties类
- kettle carte file-----------------validation.properties
- 从面试中的总结
- MFC如何使控件大小随着对话框大小自动调整
- Java基础介绍(英文)
- ProgressBar的简单使用
- poj_2352Stars
- File(二) Properties
- Fabonaccai(一)
- 最近看过的书单(2)
- 英文面试
- UVa 10738 - Riemann vs Mertens
- WinUSBeasy
- JAVA学习一
- 时间的跳跃处理
- Procmon 的使用