首页 > 解决方案 > 文件名、目录名或卷标语法不正确[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] 文件名、目录名或卷标语法不正确”错误。

我已经寻找解决方案,但它没有解决我的问题。你们能帮我了解问题的根本原因以及可能的解决方案吗?

先感谢您。

标签: javaseleniummavenappiumtestng.xml

解决方案


推荐阅读