用java读取各种计算机文件系统的文件列表(转)
来源:互联网 发布:好看的古装剧 知乎 编辑:程序博客网 时间:2024/05/23 01:12
用java读取各种计算机文件系统的文件列表
/**
* @author jackliu
* by: http://wwww.cn-java.com
*/
import java.io.File;
import java.util.Date;
import java.util.Iterator;
import java.util.Vector;
public class FileViewer{
File myDir;
File[] contents;
Vector vectorList;
Iterator currentFileView;
File currentFile;
String path;
public FileViewer(){
path=new String("");
vectorList=new Vector();
}
public FileViewer(String path){
this.path=path;
vectorList=new Vector();
}
/**
* 设置浏览的路径
*/
public void setPath(String path){
this.path=path;
}
/***
* 返回当前目录路径
*/
public String getDirectory(){
return myDir.getPath();
}
/**
* 刷新列表
*/
public void refreshList(){
if(this.path.equals("")) path="c://";
myDir=new File(path);
vectorList.clear();
contents =myDir.listFiles();
//重新装入路径下文件
for(int i=0;i<contents.length;i++){
vectorList.add(contents[i]);
}
currentFileView=vectorList.iterator();
}
/**
* 移动当前文件集合的指针指到下一个条目
* @return 成功返回true,否则false
*/
public boolean nextFile(){
while(currentFileView.hasNext()){
currentFile=(File)currentFileView.next();
return true;
}
return false;
}
/**
* 返回当前指向的文件对象的文件名称
*/
public String getFileName(){
return currentFile.getName();
}
/**
* 返回当前指向的文件对象的文件尺寸
*/
public String getFileSize(){
return new Long(currentFile.length()).toString();
}
/**
* 返回当前指向的文件对象的最后修改日期
*/
public String getFileTimeStamp(){
return new Date(currentFile.lastModified()).toString();
}
/**
* 返回当前指向的文件对象是否是一个文件目录
*/
public boolean getFileType(){
return currentFile.isDirectory();
}
}
/**
* @author jackliu
* by: http://wwww.cn-java.com
*/
import java.io.*;
public class test{
public static void main(String[] args){
System.out.println("File List");
FileViewer f=new FileViewer();
f.setPath("d://");
f.refreshList();
while(f.nextFile()){
System.out.print(f.getFileName());
if(!f.getFileType())
System.out.print(" "+f.getFileSize());
else
System.out.print(" <DIR>");
System.out.print(f.getFileTimeStamp()+"/n");
}
}
}
- 用java读取各种计算机文件系统的文件列表
- 用java读取各种计算机文件系统的文件列表
- 用java读取各种计算机文件系统的文件列表(转)
- 用Java实现读取计算机目录的文件
- java 读取 properties文件的各种方法
- java各种读取文件的方法
- Java 读取 Hadoop 文件系统 文件
- HDFS文件系统在JAVA中的操作(1) 读取文件
- java读取文件的各种方法汇总笔记
- Java中对文件列表的读取和筛选
- Java读取指定路径下的文件列表
- java各种读取properties文件方法
- java各种读取properties文件方法
- java各种IO读取文件对比
- java各种读取properties文件方法
- java读取文件列表后排序
- 跟踪计算机视觉前沿必读的列表(各种论文)
- 各种shell的初始化文件列表
- 欢迎大家加入百度编程俱乐部!
- 考试
- 晒晒我们的面试题(转)
- 《软件自动化测试成功之道》新书出版
- 不知道写什么。
- 用java读取各种计算机文件系统的文件列表(转)
- 数学之美番外篇:快排为什么那样快
- 工厂方法模式(Factory Method)
- Real British English : Larks and owls
- 4
- 怎么解决网页中播放视频没有声音?
- 初学的疑问
- 我是新来的 ?
- rule 规则