IO流-获取指定目录下文件夹和文件对象【File类】
一、运用File类实现获取指定目录下文件夹和文件对象
1、File类
2、方法:
获取文件绝对路径 :getAbsolutePath
案例:
import java.io.File;
/**
* 获取指定目录下文件夹和文件对象
* Created by lcj on 2017/11/7.
*/
public class fileTest03 {
public static void main(String[] args) {
File dirr = new File("D:\\xuexiziliao");
listAll(dirr,0);
} public static void listAll(File dirr,int leven) {
//getAbsolutePath :获取文件绝对路径
System.out.println(getSpace(leven) + dirr.getAbsolutePath());
leven ++;
//获取指定目录下文件夹和文件对象
File[] files = dirr.listFiles();
for (int i=0;i<files.length;i++)
{
//isDirectory判断是否是目录,如是,则迭代执行listAll方法
if (files[i].isDirectory())
{
listAll(files[i],leven);
}else
{
System.out.println(getSpace(leven)+ files[i].getAbsolutePath());
}
}
} public static String getSpace(int leven) {
//StringBuilder可变字符序列
StringBuilder sb = new StringBuilder();
sb.append("|--");
for(int X = 0; X<=leven;X++)
{
sb.insert(0, "| ");
}
return sb.toString();
}
}
IO流-获取指定目录下文件夹和文件对象【File类】的更多相关文章
- 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本
摘自:http://blog.csdn.net/forandever/article/details/5711319 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本 ...
- qt获取指定目录下符合条件的文件路径
1)设置名称过滤器 QDir * dir = new QDir(路径); QStringList filter; Filter << QStringLiteral(“筛选的文件条件,如.x ...
- php获取指定目录下的所有文件列表
在我们实际的开发需求中,经常用到操作文件,今天就讲一下关于获取指定目录下的所有文件的几种常用方法: 1.scandir()函数 scandir() 函数返回指定目录中的文件和目录的数组. scandi ...
- C++:获取指定目录下的所有文件
1.获得指定目录下的所有文件(不搜索子文件夹) 需要包含的头文件 #include <io.h> #include <string> #include <vector&g ...
- TDirectory.GetFileSystemEntries获取指定目录下的目录和文件
使用函数: System.IOUtils.TDirectory.GetFileSystemEntries 所有重载: class function GetFileSystemEntries(const ...
- c# 获取指定目录下的所有文件并显示在网页上
参考文献: FileInfo 的使用 https://msdn.microsoft.com/zh-cn/library/system.io.fileinfo_methods(v=vs.110).as ...
- <UnityTheGreat><001>获取指定目录下指定类型的所有文件的名称
#region Environment Windows 10 Unity 2019.4.16f1c1 LTS VSCode 1.52 https://github.com/MirzkisD1Ex0/U ...
- PHP 获取指定目录下所有文件(包含子目录)
PHP 获取指定目录下所有文件(包含子目录) //glob — 寻找与模式匹配的文件路径 $filter_dir = array('CVS', 'templates_c', 'log', 'img', ...
- TDirectory.GetFiles获取指定目录下的文件
使用函数: System.IOUtils.TDirectory.GetFiles 所有重载: class function GetFiles(const Path: string): TStringD ...
随机推荐
- centos7 rsync+inotify软件实现集群服务的数据备份(一)
一.rsync软件的说明: 1.1 什么是rsync rsync是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.它使用所谓的“Rsync演算法”来使本地和远程两个主机之间的文件达 ...
- CSS3---关于背景
1.background-origin:设置元素背景图片的原始起始位置. background-origin : border-box | padding-box | content-box; ...
- npm start问题
问题:在执行命令npm start 是出现下列问题: npm [] WARN invalid config loglevel="notice" [] npm WARN invali ...
- 前端传list,springmvc接收list的方法
handler: function() { var baseCustomerForm = me.getAddBaseCustomerForm().getForm(); var linkStore = ...
- HDU 5421 Victor and String
Victor and String Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on HDU. Orig ...
- python008 Python3 字符串
var1 = 'Hello World!' var2 = "QQ603374730" Python 访问字符串中的值Python 不支持单字符类型,单字符也在Python也是作为一 ...
- [luoguP2564][SCOI2009]生日礼物(队列)
传送门 当然可以用队列来搞啦. # include <iostream> # include <cstdio> # include <cstring> # incl ...
- 洛谷P1771 方程的解_NOI导刊2010提高(01)
题目描述 佳佳碰到了一个难题,请你来帮忙解决. 对于不定方程a1+a2+…+ak-1+ak=g(x),其中k≥2且k∈N,x是正整数,g(x)=x^x mod 1000(即x^x除以1000的余数), ...
- 【链表】2017多校训练三 HDU 6058 Kanade's sum
acm.hdu.edu.cn/showproblem.php?pid=6058 [题意] 给定一个排列,计算 [思路] 计算排列A中每个数的贡献,即对于每个ai,计算有ni个区间满足ai是区间中的第k ...
- private、protected和public的区别
private 是完全私有的,只有当前类中的成员能访问到. protected 是受保护的,只有当前类的成员与继承该类的类才能访问. 这两个是访问类中成员权限的限制符.在类外如果想使用类中的成员,只能 ...