java课程设计 博客园_《Java课程设计》

一。 本组课题

简易文件资源管理器

需求分析

查找文件功能:可以根据指定的目录名与待查找的文件,在指定目录中进行查找,并返回结果

实现文件的拷贝与粘贴功能

实现文本类文件(.txt, .java, .ini, .bat, )的预览功能(比如实现对前100行文本在某个小窗口中进行预览)

实现文件的重命名功能

实现对某个文件夹进行统计功能(如统计文件夹中文件数目)

在安卓系统上实现

本人任务

1. 对文件及文件夹进行拷贝和剪切的功能。

二. 总体设计(概要设计)

主要设计为Folder类和Filel类

b42f8b8283a9eb51961ca6ba1460c6be.png

Folder类

提供绝对路径为参数获取对象

可获得目录的各种信息

并提供格式化size数据的方法

d6619ecd483c9e39f91def2e9daa4af2.png

Filel类

直接继承File类,简化设计

提供复制文件或为文件夹的方法

6d384bdb7d8ed8c79bfb773f37d72ca7.png

APP基于安卓API18

主Activiy继承于ListView直接显示根目录

视图使用Listview与继承自BaseAdapter的自定义适配器组合

适配器getview中使用convertView,holder静态类加快UI流畅性

三. 是西安功能的主要代码块

package test;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

public class File1 extends File{

public File1(String path) {

super(path);

// TODO Auto-generated constructor stub

}

/**

* 复制选择

* @param destDir

* @param delscr

* @return

*/

public boolean copyTo(String destDir,boolean delscr){

File file = new File(super.getPath());

if(file.isDirectory())

return copyDirectory(super.getPath(), destDir,delscr);

else

return copyFile(super.getPath(), destDir,delscr);

}

/**

* 复制文件

* @param scrPath

* @param destDir

* @param delscr

* @return

*/

private boolean copyFile(String scrPath, String destDir,boolean delscr) {

boolean flag = false;

File file = new File(scrPath);

String filename =file.getName();

String destPath ;

if(destDir.equals("/")){

destPath = destDir+filename;

}

else{

destPath = destDir+"/"+filename;

}

File destFile = new File(destPath);

if(destFile.exists()&&destFile.isFile()){

System.out.println("目标目录下已有同名文件");

return false;

}

File newfile = new File(destPath);

try{

FileInputStream fis = new FileInputStream(scrPath);

FileOutputStream fos = new FileOutputStream(newfile);

byte[]buf =new byte[1024];

int c;

while((c=fis.read(buf))!=-1){

fos.write(buf,0,c);

}

fis.close();

fos.close();

flag=true;

}catch(IOException e){

}

if(flag){

System.out.println("复制成功");

}

if(delscr == true){

file.delete();

}

return flag;

}

/**

* 复制文件夹

* @param scrPath

* @param destDir

* @param delscr

* @return

*/

private boolean copyDirectory(String scrPath, String destDir,boolean delscr) {

boolean flag = false;

File scrFile = new File(scrPath);

String dirName = scrFile.getName();

String destPath ;

if(destDir.equals("/")){

destPath = destDir+dirName;

}

else{

destPath = destDir+"/"+dirName;

}

File[] files = scrFile.listFiles();

File desdir = new File(destPath);

if(desdir.exists()&&desdir.isDirectory()){

return false;

}

desdir.mkdir();

for(File f:files){

if(f.isDirectory()){

copyDirectory(f.getPath(),desdir.getPath(),delscr);

}

if(f.isFile()){

copyFile(f.getPath(),destPath,delscr);

flag = true;

}

}

if(delscr == true){

scrFile.delete();

}

return flag;

}

}

四. 功能运行的成功界面

e07383dcdd85796964089ae3316f0b41.png

f528a38b1a93e228efe4768984c235ad.png

5001289eb5f991258082b0e4e35e85f4.png

0ef8cec7db1754691de33963328c9ac8.png

5b7fbcc78afb64a85d5b81443521e878.png

207ef3668567866f81141f20927a8769.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值