Java 基于命令行文件管理器
package filemanager;
import java.io.*;
import java.security.*;
import java.util.*;
import javax.crypto.*;
public class FileManager {
public static void main(String[] args) throws Exception {
MainMenu mainmenu=new MainMenu();
mainmenu.StartMenu();
}
}
class CreateFile{
CreateFile() throws IOException{
Scanner s=new Scanner(System.in);
System.out.println("Where to create?(D:/aaa/...)");
String CurrentDirectory=s.next();
File file=new File(CurrentDirectory);
if(file.exists()){
System.out.println("Enter the name:");
String Name=s.next();
File f = new File(CurrentDirectory+File.separator+Name) ;// 实例化File类的对象
f.mkdir() ;
System.out.println("success to create!");
}else System.out.println("the directory isn't exist!");
}
}
class DeleteFile{
File path;
public DeleteFile(File path){
this.path=path;
}
public void Delete(File path){
File filelist[]=path.listFiles();
int listlen=filelist.length;
for(int i=0;i<listlen;i++){
if(filelist[i].isDirectory()){
Delete(filelist[i]);
}
else {
filelist[i].delete();
}
}
path.delete();//删除当前目录
}
void Success(){
System.out.println("Success to delete!!:");
}
}
class EnterDirectory{
EnterDirectory(String path) throws IOException{
Runtime.getRuntime().exec("explorer.exe " + path);
}
}
class ListDirectory{
ListDirectory(String path){
// String luj=null;//路径
//如果dir不以文件分隔符结尾,自动添加文件分隔符
if(!path.endsWith(File.separator)){
path = path + File.separator;
}
File dirFile = new File(path);
//如果dir对应的文件不存在,或者不是一个文件夹则退出
if(!dirFile.exists() || (!dirFile.isDirectory())){
System.out.println("List failed!cannot find the directory:"+path);
}
//list方法返回该目录下的所有文件(包括目录)的文件名,文件名不含路径信息
System.out.println(path+" contains below directorise or files");
String[] files = dirFile.list();
for(int i = 0; i < files.length; i++){
System.out.println(files[i]);
}
}
}
class CopyFile{
CopyFile(String source, String dest) throws IOException {
File in = new File(source);
File out = new File(dest);
FileInputStream inFile = new FileInputStream(in);
FileOutputStream outFile = new FileOutputStream(out);
byte[] buffer = new byte[1024];
int i = 0;
while ((i = inFile.read(buffer)) != -1) {
outFile.write(buffer, 0, i);
}//end while
inFile.close();
outFile.close();
System.out.print("Success to copy!");
}
}
class CopyDirectory{
public void copyFolder(String oldPath, String newPath) {
try {
(new File(newPath)).mkdirs(); //如果文件夹不存在 则建立新文件夹
File a=new File(oldPath);
String[] file=a.list();
File temp=null;
for (int i = 0; i < file.length; i++) {
if(oldPath.endsWith(File.separator)){
temp=new File(oldPath+file[i]);
}
else{
temp=new File(oldPath+File.separator+file[i]);
}
if(temp.isFile()){
FileInputStream input = new FileInputStream(temp);
FileOutputStream output = new FileOutputStream(newPath + "/" + (temp.getName()).toString());
byte[] b = new byte[1024 * 5];
int len;
while ( (len = input.read(b)) != -1) {
output.write(b, 0, len);
}
output.flush();
output.close();
input.close();
}
if(temp.isDirectory()){//如果是子文件夹
copyFolder(oldPath+"/"+file[i],newPath+"/"+file[i]);
}
}
}
catch (Exception e) {
System.out.println("复制整个文件夹内容操作出错");
e.printStackTrace();
}
}
public void Success(){
System.out.println("Success to copy the directory!");
}
}
class TestDES {
Key key;
public TestDES(){}
public TestDES(String str) {
getKey(str);//生成密匙
}
/**
* 根据参数生成KEY */ public void getKey(String strKey) { try { KeyGenerator _generator = KeyGenerator.getInstance("DES"); _generator.init(new SecureRandom(strKey.getBytes())); this.key = _generator.generateKey(); _generator = null; } catch (Exception e) { throw new RuntimeException("Error initializing SqlMap class. Cause: " + e); } } /* * 文件file进行加密并保存目标文件destFile中 * * @param file 要加密的文件 如c:/test/srcFile.txt * @param destFile 加密后存放的文件名 如c:/加密后文件.txt */
public void encrypt(String file, String destFile) throws Exception { //【具体用法见主函数】
Cipher cipher = Cipher.getInstance("DES");
// cipher.init(Cipher.ENCRYPT_MODE, getKey());
cipher.init(Cipher.ENCRYPT_MODE, this.key);
InputStream is = new FileInputStream(file);
OutputStream out = new FileOutputStream(destFile);
CipherInputStream cis = new CipherInputStream(is, cipher);
byte[] buffer = new byte[1024];
int r;
while ((r = cis.read(buffer)) > 0) {
out.write(buffer, 0, r);
}
cis.close();
is.close(); out.close(); } /* * 文件采用DES算法解密文件 * * @param file 已加密的文件 如c:/加密后文件.txt * * @param destFile * 解密后存放的文件名 如c:/ test/解密后文件.txt */ public void decrypt(String file, String dest) throws Exception { Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.DECRYPT_MODE, this.key); …… 此处隐藏:5607字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [互联网资料]2022年厦门大学机电工程系824机械设计
- [互联网资料]东南大学2022年硕士研究生拟录取名单公
- [互联网资料]能源调研报告(精选多篇)
- [互联网资料]初三英语下学期 中考英语 语法填空训练
- [互联网资料]2022内蒙古选调生行测常识备考:新事物
- [互联网资料]自驾必备!在新西兰租什么样的车自驾游
- [互联网资料]佛教素食菜谱44页未完
- [互联网资料]盈利能力分析外文翻译
- [互联网资料]2022年南昌航空大学音乐学院736马克思
- [互联网资料]优选外贸跟单实习报告总结(精品版)
- [互联网资料]银行新员工培训总结
- [互联网资料]2_year_visa_new_guidance_190316
- [互联网资料]天津市五校宝坻一中静海一中杨村一中芦
- [互联网资料]2007--2008学年第一学期高三数学宁波市
- [互联网资料]Chromatic framework for vision in ba
- [互联网资料]幼儿园大班上学期美术教案《心愿树》含
- [互联网资料]2022年华中农业大学信息学院820微型计
- [互联网资料]硬盘坏道的表现 __硬盘使用久了
- [互联网资料]江苏省2016年会计从业资格考试《会计基
- [互联网资料]公共场所卫生监督试卷全解
- 高级英语第一册所有修辞方法及例子总结
- 综合交通枢纽规划与城市发展
- 沃尔玛的企业文化案例分析
- 美国Thanksgiving Day 感恩节 介绍
- PEP六年级英语上册Unit6How do you fee
- 最齐全的中国大型商场购物中心名单
- 数据结构实验报告八—哈夫曼编译码
- 杭州市余杭区人民政府(通知)
- 七年级语文成语运用专项训练
- 微观经济学第三章 消费者行为 课后习题
- 对_钱学森之问_的思考
- Excel_三级联动_下拉菜单
- 办公用品需求计划申请表
- 对外汉语教材必须要知道的发展史
- 挑战杯大学生学术科技作品竞赛作品申报
- 举办民办教育培训机构应具备下列条件
- 太阳能路灯项目设计方案
- 2013年八年级上最新人教版新教材Unit3I
- 【历史】 6-4 《近代科学之父牛顿》 课
- 高中生物《第四章 第二节 探讨加酶洗衣




