【新增】 1、判分完成后,上传文件 2、选择题判分 3、获取学生成绩

This commit is contained in:
RENWEIBING\letre
2025-05-07 16:02:20 +08:00
parent 5ec805e0a8
commit 6c5197fab7
17 changed files with 626 additions and 77 deletions

View File

@@ -8,6 +8,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pc.exam.pp.framework.common.pojo.CommonResult;
import pc.exam.pp.module.exam.dal.mysql.student.StuScoreVo;
import pc.exam.pp.module.exam.service.stuPaperScore.StuPaperScoreService;
import pc.exam.pp.module.judgement.controller.admin.autoTools.vo.StuPaperReqVo;
import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService;
@@ -18,9 +20,16 @@ import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService;
public class AutoToolsController {
@Resource
private AutoToolsService autoToolsService;
@Resource
StuPaperScoreService stuPaperScoreService;
@GetMapping("/get")
public CommonResult<Double> get(StuPaperReqVo stuPaperReqVo) throws Exception {
return autoToolsService.judgementScore(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId());
}
@GetMapping("/get_stu_score")
public CommonResult<StuScoreVo> getStuScore(StuPaperReqVo stuPaperReqVo){
return CommonResult.success(stuPaperScoreService.getStuScore(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId()));
}
}

View File

@@ -1,30 +1,44 @@
package pc.exam.pp.module.judgement.service.auto_tools;
import cn.hutool.core.io.IoUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Resource;
import lombok.Data;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.springframework.stereotype.Service;
import pc.exam.pp.framework.common.exception.ErrorCode;
import org.springframework.web.multipart.MultipartFile;
import pc.exam.pp.framework.common.pojo.CommonResult;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperFileDO;
import pc.exam.pp.module.exam.dal.dataobject.student.StuPaperScoreDO;
import pc.exam.pp.module.exam.dal.mysql.student.StuPaperScoreMapper;
import pc.exam.pp.module.exam.service.question.IExamQuestionService;
import pc.exam.pp.module.exam.service.stuPaperScore.StuPaperScoreService;
import pc.exam.pp.module.exam.service.stu_paper_file.StuPaperFileService;
import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO;
import pc.exam.pp.module.infra.service.config.ConfigService;
import pc.exam.pp.module.infra.service.file.FileService;
import pc.exam.pp.module.judgement.controller.service.browser.IBrowserServerice;
import pc.exam.pp.module.judgement.controller.service.file.IFileServerice;
import pc.exam.pp.module.judgement.controller.service.mysql.IMysqlServerice;
import pc.exam.pp.module.judgement.service.c_programming.JudgementService;
import pc.exam.pp.module.judgement.service.choice.JudgementChoiceService;
import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService;
import pc.exam.pp.module.judgement.utils.JudgementCUtils;
import pc.exam.pp.module.judgement.utils.multipartFile.CustomMultipartFile;
import pc.exam.pp.module.judgement.utils.zipfile.FolderZipper;
import java.io.*;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
@Service
public class AutoToolsServiceImpl implements AutoToolsService{
@@ -44,6 +58,15 @@ public class AutoToolsServiceImpl implements AutoToolsService{
IFileServerice fileServerice;
@Resource
IBrowserServerice browserServerice;
@Resource
FileService fileService;
@Resource
StuPaperScoreService stuPaperScoreService;
@Resource
StuPaperScoreMapper stuPaperScoreMapper;
@Resource
JudgementChoiceService judgementChoiceService;
@Override
public String downloadStudentFile(String fileUrl, String filePath) {
try {
@@ -125,8 +148,17 @@ public class AutoToolsServiceImpl implements AutoToolsService{
}
}
/**
* 试卷得整体判分
* @param stuId 学号
* @param paperId 试卷ID
* @return 分数
* @throws Exception 异常
*/
@Override
public CommonResult<Double> judgementScore(Long stuId, String paperId) throws Exception {
// 获取平台文件参数
ConfigDO config = configService.getConfigByKey("file_down_path");
double score = 0;
// 1、通过学号,试卷ID查询文件路径
List<StuPaperFileDO> stuPaperFileDOList = stuPaperFileService.findByStuIDAndPaperId(stuId, paperId);
@@ -140,14 +172,30 @@ public class AutoToolsServiceImpl implements AutoToolsService{
stuPaperFileDO = stuPaperFileDOs;
}
}
// 1-1、 穿插选择题判分
// 1-1-1、下载选择题文件
String select_qu = downloadStudentFile(noZipFileDO.getUrl(), config.getValue());
File select_file = new File(select_qu);
// 1-1-2、读取内容转换成json
String select_string = readFileAsString(select_file.getPath());
Stu stu = stringToJson(select_string);
// 1-1-3、进行选择题判分
for (String key : stu.getQuestionResultMap().keySet()) {
String value = stu.getQuestionResultMap().get(key);
double select_score = judgementChoiceService.ProgrammingChoice(1.0, key, value);
score += select_score;
}
// 1-1-4、删除文件
select_file.delete();
// 2、判断文件路径是否存在
if (stuPaperFileDO == null) {
return CommonResult.error(100031, "试题文件没有上传,无法判分!");
}
// 3、下载文件
// 获取平台文件参数
ConfigDO config = configService.getConfigByKey("file_down_path");
String patn = downloadStudentFile(stuPaperFileDO.getUrl(), config.getValue());
File zip_file = new File(patn);
// 4、获取到得是zip文件需要解压
String stuFilePath = unzipToNamedFolder(patn);
// 5、解压之后得文件获取文件夹和文件
@@ -174,52 +222,106 @@ public class AutoToolsServiceImpl implements AutoToolsService{
File[] filess_qu = qu_files.listFiles();
if (filess_qu == null) return CommonResult.error(100040, "没有试题文件!");
for (File file : filess_qu) {
// 6、根据试题ID查询试题详情
ExamQuestion examQuestion = examQuestionService.selectExamQuestionByQuId(file.getName());
// 7、进行对应得判分
// --- 7.1、查询试题文件
File qu_file = new File(file.getPath());
File[] qu_file_list = qu_file.listFiles();
if (qu_file_list == null) continue;
// --- 7.2、通过文件名称进行判分
for (File file_one : qu_file_list) {
// 判断名称 类似于 C语言程序设计。 课程+题型
if (file_one.getName().split("\\.")[0].equals(examQuestion.getSubjectName()+examQuestion.getCourseName())) {
double c_score = judgementService.ProgrammingC(15.0, file.getPath(), file_one.getName(), examQuestion);
score += c_score;
break;
// ** 接下来已经到了,每个课程题型了 file 得名称
// 5.3、查询出来所有试题
File cs_files = new File(file.getPath());
// 所有试题文件
File[] cs_file_list = cs_files.listFiles();
for (File one_file : cs_file_list) {
// 6、根据试题ID查询试题详情
String qu_id = one_file.getName();
ExamQuestion examQuestion = examQuestionService.selectExamQuestionByQuId(qu_id);
if (examQuestion != null) {
// 7、进行对应得判分
// --- 7.1、查询试题文件
File qu_file = new File(one_file.getPath());
File[] qu_file_list = qu_file.listFiles();
if (qu_file_list == null) continue;
// --- 7.2、通过文件名称进行判分
for (File file_one : qu_file_list) {
// 判断名称 类似于 C语言程序设计。 课程+题型
if (file_one.getName().split("\\.")[0].equals(examQuestion.getCourseName()+examQuestion.getSubjectName())) {
double c_score = judgementService.ProgrammingC(15.0, one_file.getPath(), file_one.getName(), examQuestion);
score += c_score;
break;
}
// wps 类型存在多级文文件夹,需要个性化设置
if (file_one.getName().split("\\.")[0].equals("文档")) {
double wps_word_score = judgementWpsWordService.judgementWpsWord(15.0, one_file.getPath(), file_one.getPath(), examQuestion);
score += wps_word_score;
break;
}
// D:\1d70c404e6d42d144d0028496e893565dd2dec447f7e9b1db66466f00472424d\160\cb3cc9089b104a1e9e92deb330d0cfe8\d9f988d5ae6d435ba12d4d979d044219\stu
//windows文件处理
if (file_one.getName().equals("stu")) {
File win_file = new File(file_one.getPath());
double win_file_score = fileServerice.run_file_point(20.0,win_file, examQuestion);
score += win_file_score;
}
System.out.println(file_one);
//浏览器操作
// if ("浏览器网络题".equals(examQuestion.getCourseName()+examQuestion.getSubjectName())){
if (file_one.getName().equals("edge")) {
File edge_file = new File(file_one.getPath());
double browse_score= browserServerice.Judgement(20.0,edge_file,examQuestion);
score += browse_score;
}
}
ExamQuestion mysql=new ExamQuestion();
double judgement = mysqlServerice.Judgement(20, mysql);
score+=judgement;
}
// wps 类型存在多级文文件夹,需要个性化设置
if (file_one.getName().split("\\.")[0].equals("文档")) {
double wps_word_score = judgementWpsWordService.judgementWpsWord(15.0, file_one.getPath(), examQuestion);
score += wps_word_score;
break;
}
// D:\1d70c404e6d42d144d0028496e893565dd2dec447f7e9b1db66466f00472424d\160\cb3cc9089b104a1e9e92deb330d0cfe8\d9f988d5ae6d435ba12d4d979d044219\stu
//windows文件处理
if (file_one.getName().equals("stu")) {
File win_file = new File(file_one.getPath());
double win_file_score = fileServerice.run_file_point(20.0,win_file, examQuestion);
score += win_file_score;
}
System.out.println(file_one);
//浏览器操作
// if ("浏览器网络题".equals(examQuestion.getCourseName()+examQuestion.getSubjectName())){
if (file_one.getName().equals("edge")) {
File edge_file = new File(file_one.getPath());
double browse_score= browserServerice.Judgement(20.0,edge_file,examQuestion);
score += browse_score;
}
}
ExamQuestion mysql=new ExamQuestion();
double judgement = mysqlServerice.Judgement(20, mysql);
score+=judgement;
}
// 8、将解压之后得问及那继续重新压缩并上传到服务器并删除文件和文件夹
String zipPath = FolderZipper.zipFolder(files[0].getPath());
// 9、上传文件
MultipartFile file = new CustomMultipartFile(zipPath);
String path = null;
fileService.createStuFile(stuId, paperId, file.getOriginalFilename(), path, IoUtil.readBytes(file.getInputStream()));
// 10、将分数存入数据库
StuPaperScoreDO stuPaperScoreDO = new StuPaperScoreDO();
stuPaperScoreDO.setStuId(stuId);
stuPaperScoreDO.setPaperId(paperId);
stuPaperScoreDO.setAllScore(new BigDecimal(score));
stuPaperScoreService.insertStuPaperScore(stuPaperScoreDO);
// end、删除文件
zip_file.delete();
folder.delete();
return CommonResult.success(score);
}
/**
* 读取学生选择题答案
* @param filePath 文件路径
* @return 文本
* @throws IOException 异常
*/
public static String readFileAsString(String filePath) throws IOException {
return new String(Files.readAllBytes(Paths.get(filePath)));
}
/**
* string to java对象
* @param text 文本
* @return java对象
* @throws JsonProcessingException json异常
*/
public static Stu stringToJson(String text) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
Stu stu = mapper.readValue(text, Stu.class);
return stu;
}
/**
* 转换Java对象
*/
@Data
static class Stu {
private String stuId;
private String paperId;
private String taskId;
private Map<String, String> questionResultMap;
}
}

View File

@@ -14,9 +14,9 @@ public interface JudgementChoiceService {
/**
*
* @param score 题分
* @param examQuestion 选择题内容(学生答题)
* @param originalExamQuestion 原始题(判断答案)
* @param quId 试题ID
* @param answerId 学生选择答案ID
* @return 得分
*/
public double ProgrammingChoice(double score, ExamQuestion examQuestion, ExamQuestion originalExamQuestion);
public double ProgrammingChoice(double score, String quId, String answerId);
}

View File

@@ -1,8 +1,10 @@
package pc.exam.pp.module.judgement.service.choice;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
import pc.exam.pp.module.exam.service.question.IExamQuestionService;
/**
* 判分逻辑集合
@@ -12,43 +14,32 @@ import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
@Service
public class JudgementChoiceServiceImpl implements JudgementChoiceService
{
@Resource
IExamQuestionService examQuestionService;
/**
* 选择题判分
* @param examQuestion 选择题内容(学生答题)
* @param originalExamQuestion 原始题(判断答案)
* @param score 分数
* @return 返回判
*
* @param score 题分
* @param quId 试题ID
* @param answerId 学生选择答案ID
* @return
*/
public double ProgrammingChoice(double score, ExamQuestion examQuestion, ExamQuestion originalExamQuestion) {
// 总分重置
double totalScore = 0;
String right_id = null;
String stu_right_id = null;
public double ProgrammingChoice(double score, String quId, String answerId) {
ExamQuestionAnswer answer = new ExamQuestionAnswer();
ExamQuestion examQuestion = examQuestionService.selectExamQuestionByQuId(quId);
// 获取选择题的标准答案
// 找到对应正确题的答案ID
for (ExamQuestionAnswer examQuestionAnswer : originalExamQuestion.getAnswerList()) {
// 判断正确答案
if ("0".equals(examQuestionAnswer.getIsRight())) {
// 正确答案
right_id = examQuestionAnswer.getAnswerId();
break;
}
}
// 获取学生的做题答案,进行判断是否一致
for (ExamQuestionAnswer examQuestionAnswer : examQuestion.getAnswerList()) {
// 判断正确答案
if ("0".equals(examQuestionAnswer.getIsRight())) {
// 正确答案
stu_right_id = examQuestionAnswer.getAnswerId();
answer = examQuestionAnswer;
break;
}
}
// 判断
if (stu_right_id.equals(right_id)) {
totalScore += score;
if (answer.getAnswerId().equals(answerId)) {
return score;
} else {
return 0;
}
// 该题得分返回
return totalScore;
}
}

View File

@@ -0,0 +1,25 @@
package pc.exam.pp.module.judgement.service.wps_excel;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO;
import java.io.FileNotFoundException;
import java.util.List;
/**
* 判分逻辑集合wps excel
*
* @author rwb
*/
public interface JudgementWpsExcelService {
/**
* 获取word文件内得考点及描述
* @param path minio文件路径
* @return 文件内得考点及描述
* @throws Exception 异常
*/
public String ProgrammingWpsExcel(String path) throws FileNotFoundException;
}

View File

@@ -0,0 +1,53 @@
package pc.exam.pp.module.judgement.service.wps_excel;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO;
import pc.exam.pp.module.infra.service.config.ConfigService;
import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordListReqVO;
import pc.exam.pp.module.judgement.dal.dataobject.wpsword.WpsWordLinkDO;
import pc.exam.pp.module.judgement.dal.mysql.wpsword.WpsWordLinkMapper;
import pc.exam.pp.module.judgement.service.auto_tools.AutoToolsService;
import pc.exam.pp.module.judgement.utils.wps_excel.WpsExcelUtils;
import pc.exam.pp.module.judgement.utils.wps_word.WpsWordUtils;
import pc.exam.pp.module.judgement.utils.wps_word.vo.WordVO;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
@Service
public class JudgementWpsExcelServiceImpl implements JudgementWpsExcelService {
@Resource
WpsWordLinkMapper wpsWordLinkMapper;
@Resource
AutoToolsService autoToolsService;
@Resource
ConfigService configService;
@Override
public String ProgrammingWpsExcel(String path) throws FileNotFoundException {
// // 1、获取文件临时下载路径
// ConfigDO config = configService.getConfigByKey("file_down_path");
// // 2、下载文件并返回文件完整路径
// String pathName = autoToolsService.downloadStudentFile(path, config.getValue());
// // 3、创建word考点tree
// WordListReqVO wordListReqVO = new WordListReqVO();
// wordListReqVO.setBelongTo(0);
// List<WpsWordLinkDO> list = wpsWordLinkMapper.selectList(wordListReqVO);
// // 4、docx文件读取并返回考点及说明信息
path = "D:\\Code\\exam\\word\\202504171100_wps表格处理\\202504171100_wps表格处理\\885\\ET_001_319\\结果素材\\文档.xlsx";
String margins1 = WpsExcelUtils.wps_excel(path);
// // 5、已经读取完得考点删除源文件
// File file = new File(pathName);
// file.delete();
return margins1;
}
}

View File

@@ -31,5 +31,5 @@ public interface JudgementWpsWordService {
* @return 得分
* @throws Exception 异常
*/
public double judgementWpsWord(double sorce, String path, ExamQuestion examQuestion) throws Exception;
public double judgementWpsWord(double sorce, String pathC, String path, ExamQuestion examQuestion) throws Exception;
}

View File

@@ -6,6 +6,7 @@ import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestion;
import pc.exam.pp.module.exam.dal.dataobject.ExamQuestionAnswer;
import pc.exam.pp.module.exam.utils.file.LogFileUtils;
import pc.exam.pp.module.infra.dal.dataobject.config.ConfigDO;
import pc.exam.pp.module.infra.service.config.ConfigService;
import pc.exam.pp.module.judgement.controller.admin.WpsWord.vo.WordListReqVO;
@@ -51,7 +52,10 @@ public class JudgementWpsWordServiceImpl implements JudgementWpsWordService {
}
@Override
public double judgementWpsWord(double sorce, String path, ExamQuestion examQuestion) throws Exception {
public double judgementWpsWord(double sorce, String pathC, String path, ExamQuestion examQuestion) throws Exception {
// 创建log文件txt用于记录
LogFileUtils.createFile(pathC + "/log.txt");
LogFileUtils.writeLine("✅ 开始WPS_Word判分");
double wps_word_sorce = 0;
// 1、查询Word考点tree
WordListReqVO wordListReqVO = new WordListReqVO();
@@ -83,6 +87,8 @@ public class JudgementWpsWordServiceImpl implements JudgementWpsWordService {
}
}
}
// 关闭已经打开得文件
LogFileUtils.close();
return wps_word_sorce;
}

View File

@@ -0,0 +1,62 @@
package pc.exam.pp.module.judgement.utils.multipartFile;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
public class CustomMultipartFile implements MultipartFile {
private final String contentType;
private final String fileName;
private final byte[] fileContent;
public CustomMultipartFile(String filePath) throws IOException {
File file = new File(filePath);
this.fileName = file.getName();
this.fileContent = Files.readAllBytes(file.toPath());
this.contentType = Files.probeContentType(file.toPath());
}
@Override
public String getName() {
return fileName;
}
@Override
public String getOriginalFilename() {
return fileName;
}
@Override
public String getContentType() {
return contentType;
}
@Override
public boolean isEmpty() {
return fileContent == null || fileContent.length == 0;
}
@Override
public long getSize() {
return fileContent.length;
}
@Override
public byte[] getBytes() throws IOException {
return fileContent;
}
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(fileContent);
}
@Override
public void transferTo(File dest) throws IOException, IllegalStateException {
Files.write(dest.toPath(), fileContent);
}
}

View File

@@ -0,0 +1,44 @@
package pc.exam.pp.module.judgement.utils.wps_excel;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class WpsExcelUtils {
public static String wps_excel(String filePath) throws FileNotFoundException {
try (FileInputStream fis = new FileInputStream(filePath);
XSSFWorkbook workbook = new XSSFWorkbook(fis)) {
Sheet sheet = workbook.getSheetAt(0); // 读取第一个工作表
for (Row row : sheet) {
for (Cell cell : row) {
switch (cell.getCellType()) {
case STRING:
System.out.print(cell.getStringCellValue() + "\t");
break;
case NUMERIC:
System.out.print(cell.getNumericCellValue() + "\t");
break;
case BOOLEAN:
System.out.print(cell.getBooleanCellValue() + "\t");
break;
default:
System.out.print("?\t");
}
}
System.out.println();
}
} catch (IOException e) {
e.printStackTrace();
}
return filePath;
}
}

View File

@@ -0,0 +1,77 @@
package pc.exam.pp.module.judgement.utils.zipfile;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class FolderZipper {
/**
* 压缩文件夹为ZIP文件
* @param sourceFolderPath 要压缩的文件夹路径
* @return 生成的ZIP文件完整路径
* @throws IOException 如果压缩过程中出现IO错误
*/
public static String zipFolder(String sourceFolderPath) throws IOException {
// 确保源文件夹存在
File sourceFolder = new File(sourceFolderPath);
if (!sourceFolder.exists() || !sourceFolder.isDirectory()) {
throw new IllegalArgumentException("提供的路径不是一个有效的文件夹: " + sourceFolderPath);
}
// 创建ZIP文件名使用源文件夹名 + .zip
String zipFileName = sourceFolder.getName() + ".zip";
Path zipFilePath = Paths.get(sourceFolder.getParent(), zipFileName);
// 创建ZIP输出流
try (FileOutputStream fos = new FileOutputStream(zipFilePath.toFile());
ZipOutputStream zos = new ZipOutputStream(fos)) {
// 递归压缩文件夹内容
zipDirectory(sourceFolder, sourceFolder, zos);
}
return zipFilePath.toAbsolutePath().toString();
}
/**
* 递归压缩文件夹内容
* @param rootFolder 根文件夹(用于计算相对路径)
* @param currentFolder 当前处理的文件夹
* @param zos ZIP输出流
* @throws IOException 如果压缩过程中出现IO错误
*/
private static void zipDirectory(File rootFolder, File currentFolder, ZipOutputStream zos) throws IOException {
File[] files = currentFolder.listFiles();
if (files == null) return;
for (File file : files) {
if (file.isDirectory()) {
// 如果是文件夹,递归处理
zipDirectory(rootFolder, file, zos);
} else {
// 计算相对路径
String relativePath = rootFolder.toPath().relativize(file.toPath()).toString();
// 创建ZIP条目
ZipEntry zipEntry = new ZipEntry(relativePath);
zos.putNextEntry(zipEntry);
// 写入文件内容
try (FileInputStream fis = new FileInputStream(file)) {
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
}
zos.closeEntry();
}
}
}
}