滨州做网站建设价格个人网站制作网站
news/
2025/9/23 3:24:25/
文章来源:
滨州做网站建设价格,个人网站制作网站,相册模版网站图片展示,注册公司需要啥资料1、 需求
我想把资源文件先加密成压缩文件#xff0c;然后同时创建每个加密压缩文件同名的文件夹#xff0c;同时需要把这个加密文件拷贝到这个同名的文件夹#xff0c;然后还需要把一个图片和一个文本文档同时放进这个文件夹#xff0c;然后在不加密压缩这个文件夹#…1、 需求
我想把资源文件先加密成压缩文件然后同时创建每个加密压缩文件同名的文件夹同时需要把这个加密文件拷贝到这个同名的文件夹然后还需要把一个图片和一个文本文档同时放进这个文件夹然后在不加密压缩这个文件夹上传资源到百度网盘。 2、思路
1、windows环境用python来实现能实现生成同名文件夹然后拷贝文件的时候中文名的文件拷贝都文件夹有问题估计是编码格式不对对python不是很熟悉然后放弃python来处理。
2、用java来实现遍历加密文件然后创建同名不带后缀的文件夹然后把这个加密文件拷贝到这个文件夹然后删除加密文件再拷贝图片和文本到这个加密文件夹。 3、具体代码实现过程
1、批量加密文件
windows环境批量加密文件我们在需要加密的文件目录新建1.bat文件内容如下
for %%X in (*) do C:\Program Files\7-Zip\7z.exe a %%~dpnX.7z %%X -pcch1233nxecc -mhe -mx0
注意这里-p后面是密码这里的密码是cch1233nxecc用户可以自己设置点击1.bat就能加密批量压缩。
2、把压缩成7z的文件手动拿出来放到一个文件夹里面去我放在这个目录
F:\didi1\all11_30\C 3、用java代码实现创建文件夹然后放拷贝文件进去然后删除加密文件然后拷贝具体图片和文本文档到这个文件夹解压密码图片和文本地址如下
F:\\didi1\\all11_30\\解压密码.png
F:\\didi1\\all11_30\\计算机40多个方向1000多个电子书.txt
代码实现如下
package com.chenyu;import java.io.File;public class Test {public static void main(String[] args) {System.out.println(chen); String path F:\\didi1\\all11_30\\C;File decodePwdPngFile new File(F:\\didi1\\all11_30\\解压密码.png);File txtFile new File(F:\\didi1\\all11_30\\计算机40多个方向1000多个电子书.txt);FileUtil.handleFile(path, decodePwdPngFile, txtFile);}}FileUtil.java文件如下
package com.chenyu;import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.channels.FileChannel;public class FileUtil {/*** 创建新的文件夹* param file* return*/public static String getNewDirectoryPath(File file) {if (file null)return chenyu;String dirPath file.getAbsolutePath() File.separator file.getName();if (dirPath.contains(.)) {int index dirPath.indexOf(.);dirPath dirPath.substring(0, index);} else {dirPath dirPath 1;}return dirPath;}/*** 处理文件创建文件夹然后拷贝文件进去* param path*/public static void handleFile(String path, File decodePwdPngFile, File txtFile) {if (path null || .equals(path) || decodePwdPngFile null || txtFile null)return;File file new File(path);if (!file.exists())return;File[] files file.listFiles();if (files null || files.length 0)return;try {for (File childFile : files) {if (childFile.isDirectory()) {System.out.println(文件夹路径是: childFile.getAbsolutePath());handleFile(childFile.getAbsolutePath(), decodePwdPngFile, txtFile);} else {System.out.println(文件路径是: childFile.getAbsolutePath());if (childFile.getAbsolutePath() null)return;if (childFile.getName() null)return;//得到新的目录String dirPath getNewDirectoryPath(childFile);System.out.println(dirPath路径是: dirPath);File fileDir new File(dirPath);//创建新的目录if (!fileDir.exists()) {fileDir.mkdirs();}//构建资源zip文件File fileTmp new File(dirPath, childFile.getName());if (!fileTmp.exists()) {fileTmp.createNewFile();}//复制资源zip文件到新的文件夹copyFile(childFile, fileTmp);//删除zip文件childFile.delete();//拷贝图片到这个dirPath目录来File decodePwdPng new File(dirPath, 解压密码.png);if (!decodePwdPng.exists()) {decodePwdPng.createNewFile();}copyFile(decodePwdPngFile, decodePwdPng);//拷贝txt文件到这个dirPath目录来File newTxtFile new File(dirPath, 计算机40多个方向1000多个电子书.txt);if (!newTxtFile.exists()) {newTxtFile.createNewFile();}copyFile(txtFile, newTxtFile);}}} catch (Exception e) {e.printStackTrace();}}/*** 文件复制* param srcFile* param dstFile* throws IOException*/public static void copyFile(File srcFile, File dstFile) throws IOException {if (srcFile null || !srcFile.exists()) {return;}if (dstFile null || !dstFile.exists()) {return;}FileInputStream fileIns null;FileOutputStream fileOuts null;FileChannel source null;FileChannel destination null;try {fileIns new FileInputStream(srcFile);fileOuts new FileOutputStream(dstFile);source fileIns.getChannel();destination fileOuts.getChannel();destination.transferFrom(source, 0, source.size());} catch (Exception e) {e.printStackTrace();} finally {if (fileIns ! null)fileIns.close();if (fileOuts ! null)fileOuts.close();if (source ! null)source.close();if (destination ! null)destination.close();}}
}控制台打印
chen
文件路径是:F:\didi1\all11_30\C\C Primer Plus中文版.7z
dirPath路径是:F:\didi1\all11_30\C\C Primer Plus中文版
文件路径是:F:\didi1\all11_30\C\C专家编程.7z
dirPath路径是:F:\didi1\all11_30\C\C专家编程
文件路径是:F:\didi1\all11_30\C\C和指针第二版高清.7z
dirPath路径是:F:\didi1\all11_30\C\C和指针第二版高清
文件路径是:F:\didi1\all11_30\C\C语言深度解剖.7z
dirPath路径是:F:\didi1\all11_30\C\C语言深度解剖
文件路径是:F:\didi1\all11_30\C\C陷阱与缺陷.7z
dirPath路径是:F:\didi1\all11_30\C\C陷阱与缺陷
文件路径是:F:\didi1\all11_30\C\Effective C 中文版.7z
dirPath路径是:F:\didi1\all11_30\C\Effective C 中文版
文件路径是:F:\didi1\all11_30\C\Effective C(第三版中文版).7z
dirPath路径是:F:\didi1\all11_30\C\Effective C(第三版中文版)
文件路径是:F:\didi1\all11_30\C\Effective STL中文版.7z
dirPath路径是:F:\didi1\all11_30\C\Effective STL中文版
文件路径是:F:\didi1\all11_30\C\LinuxC编程一站式学习.7z
dirPath路径是:F:\didi1\all11_30\C\LinuxC编程一站式学习
文件路径是:F:\didi1\all11_30\C\More Effective C.7z
dirPath路径是:F:\didi1\all11_30\C\More Effective C
文件路径是:F:\didi1\all11_30\C\STL源码剖析侯捷译.7z
dirPath路径是:F:\didi1\all11_30\C\STL源码剖析侯捷译
文件路径是:F:\didi1\all11_30\C\UNIX编程艺术中文.7z
dirPath路径是:F:\didi1\all11_30\C\UNIX编程艺术中文
文件路径是:F:\didi1\all11_30\C\中文版CPrimer第三版.7z
dirPath路径是:F:\didi1\all11_30\C\中文版CPrimer第三版这里就可以得到我们的结果了 但是我们还需要再把这个文件夹批量不加密压缩我们依然还是新建2.bat内容如下
for /d %%X in (*) do c:\Program Files\7-Zip\7z.exe a %%X.7z %%X\
点击2.bat文件效果如下 这里的内容就是我们需要的内容然后我们需要批量单个上传我有工具非常方便。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/911227.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!