尝试将现有文件复制到新位置时,我的代码似乎抛出了空指针异常;新文件也将根据当前执行日期命名。
有什么想法吗?
public static String returnScreenshotName() {
return (System.getProperty("user.dir") + "\\target\\output\\imgs\\" + screenshotName);
}
private static void copyFileUsingStream(File source, File dest) throws IOException {
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(source);
os = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
} catch (IOException ignored) {
}
finally {
is.close();
os.close();
}
}
public static void copyLatestExtentReport() throws IOException {
try {
Date d = new Date();
String date = d.toString().replace(":", "_").replace(" ", "_");
File source = new File (System.getProperty("user.dir") + "\\output\\report1.html");
File dest = new File (System.getProperty("user.dir") + "\\output\\" + date + ".html");
copyFileUsingStream(source, dest);
}catch (IOException ignored) {
}