java - 文件名、目录名或卷标语法不正确[TestHTMLReporter]
问题描述
我正在使用java开发一个maven项目。我正在尝试在 .txt 文件中捕获系统日志并将 .txt 文件制作为 .zip 文件,然后最后删除现有的 .txt 文件。
这是for代码:
TCDate = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss").format(new Date());
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "logs.bat",
Screenshot.getRootDir()+"\\promta\\logs", testCaseName + "_" + TCDate);
File dir = new File(Screenshot.getRootDir()+"\\promta\\src\\test\\resources");
pb.directory(dir);
Process p = pb.start();
// For closing the log window
Runtime rt = Runtime.getRuntime();
rt.exec("taskkill /F /IM adb.exe /T");
Path source = Paths.get(Screenshot.getRootDir() + "\\PromTA\\logs\\" + testCaseName + "_" + TCDate + ".txt");
File f = new File(
Screenshot.getRootDir() + "\\PromTA\\logs\\" + testCaseName + "_" + TCDate + "_Compressed" + ".zip");
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(f));
FileInputStream fis = new FileInputStream(source.toFile());
ZipEntry zipEntry = new ZipEntry(source.getFileName().toString());
zos.putNextEntry(zipEntry);
byte[] buffer = new byte[1024];
int len;
while ((len = fis.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
zos.close();
fis.close();
Thread.sleep(5000);
Files.delete(source);
我使用 testNG“参数”注释从 excel 表中获得的“testCaseName” 。
该代码对我有用,并且在测试用例级别没有错误。但在执行后我得到“[TestHTMLReporter] 文件名、目录名或卷标语法不正确”错误。
我已经寻找解决方案,但它没有解决我的问题。你们能帮我了解问题的根本原因以及可能的解决方案吗?
先感谢您。
解决方案
推荐阅读
- c++ - struct 是否比嵌入式系统中的类具有更好的性能
- python - Django:ModelForm 的 kwargs
- javascript - 一个组件中的表单被其他组件提交
- c - POSIX,在 pthread_t 之间传递应用程序数据
- android - 如何在不单击按钮的情况下验证密码?
- c# - 用正则表达式替换字符串中项目的特定实例
- php - 如何设置 phpmyadmin 和 SQL 以通过 REST-api 进行消息传递?
- java - 具有多个具有 main 方法的类的 intellij 项目
- android - Android , Firebase JSON 字符串
- sql - 我想将此 NOT IN 查询实现为一系列 OUTER JOIN,以尝试优化执行