前言:本篇文章主要记录了我们小组成员java程序设计实验结果的大致内容
目录
前言:本篇文章主要记录了我们小组成员java程序设计实验结果的大致内容
一、团队成员及分工
20 信管一班李湘 | 20 信管一班刘响哲 | 20 信管一班周宇杰 |
删除和属性 | 文件的重命名 | 文本类文件的预览 |
文件的拷贝与粘贴 | 对某个文件夹进行统计 | 图形化界面 |
uml图绘画 | 团队项目博客 | 架构图制作 |
二、项目简介
查找文件功能:可以根据指定的目录名与待查找的文件,在指定目录中进行查找,并返回结果。
实现文件的拷贝与粘贴功能。
实现文本类文件(.txt, .java, .ini, .bat, )的预览功能。
实现文件的重命名功能。
实现对某个文件夹进行统计功能(如统计文件夹中文件数目)。
三、项目gitee地址
https://gitee.com/lixiang129310/
四、项目git提交记录截图
五、项目功能架构图
六、部分运行测试
七、核心代码
//统计文件夹的数目
public static int countFileNumber(File directory) {
int num = 0;
//若统计文件数目则 .isFile()
if (!directory.isDirectory()) {
return 1;
}
File[] files = directory.listFiles();
for (File direc : files) {
num += countFileNumber(direc);
}
return num;
}
//右键弹出菜单,显示位置不固定的弹窗
PopupMenu pop = new PopupMenu();
MenuItem deleteItem = new MenuItem("Delete");
MenuItem renameItem = new MenuItem("Rename");
MenuItem natrueItem = new MenuItem("Attributes");
MenuItem copyItem=new MenuItem("Copy");
MenuItem pasteItem=new MenuItem("Paste");
MenuItem otherItem=new MenuItem("All Have");
//自定义一个名为root的节点,后面作为根节点创建一棵树 NodeData是自定义节点类。
DefaultMutableTreeNode root = new DefaultMutableTreeNode(new NodeData(null,"我的电脑"));
//属性功能
natrueItem.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent event){
JDialog subDialog;
subDialog = new JDialog(jf,"属性");
subDialog.setVisible(true);
subDialog.setSize(400,400);
JTextArea text = new JTextArea();
subDialog.getContentPane().add(text);
TreePath tp=tree.getSelectionPath();//得到树状视图的被选择节点路径
String fullPath="";//得到被选择节点对应文件的完整路径信息
for(Object obj:tp.getPath()) {
String str=obj.toString();
if(str.endsWith("\\")){//处理盘符根目录问题
str=str.substring(0,str.length()-1);
}
if("".equals(fullPath)) {
fullPath+=str;
} else {
fullPath+="\\"+str;
}
}
int n=fullPath.indexOf("脑");
String sp=fullPath.substring(n+2);
File currentFile=new File(sp);
StringBuffer sb=new StringBuffer();
if(currentFile.isDirectory()) {
sb.append("文件夹路径: "+currentFile.getAbsolutePath()+"\n");
} else {
sb.append("文件路径: "+currentFile.getAbsolutePath()+"\n");
}
sb.append("是否可读 "+currentFile.canRead()+"\n");
sb.append("是否可写 "+currentFile.canWrite()+"\n");
if(!currentFile.isDirectory()) {
sb.append("文件的长度: "+currentFile.length()/(1024*1024)+"M\n");
}
SimpleDateFormat s=new SimpleDateFormat("yyyy年MM月dd日HH小时mm分钟ss秒");
sb.append("文件上次修改的时间: "+s.format(new Date(currentFile.lastModified()))+"\n");
sb.append("文件是否被隐藏: "+currentFile.isHidden()+"\n");
text.setText(sb.toString());
}
});