![](/img/trans.png)
[英]This process cannot access the file because the file is being used by another process (java.nio.file.FileSystemException) in KOTLIN
[英]How to resolve java.nio.file.FileSystemException The process cannot access the file because it is being used by another process
运行此代码时出现异常 (java.nio.file.FileSystemException)
公共字符串 getScreenShotAsBase64() 抛出 IOException {
File source = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
String path = System.getProperty("user.dir") + "/Screenshots/image.png";
FileUtils.copyFile(source, new File(path));
byte[] imageBytes = IOUtils.toByteArray(new FileInputStream(path));
return Base64.getEncoder().encodeToString(imageBytes);
}
当我尝试运行该方法时,它不起作用会抛出异常。
你的问题的原因是 Windows 不会让你的应用程序打开“Screenshots/image.png”文件进行写入,因为其他东西已经打开了它。 它只是不会。 有关 Windows 文件锁及其用途的概述,请参阅文件锁定。
这个 SuperUser Q&A 提供了多种方法来确定哪个其他应用程序持有文件锁:
您在这种情况下使用 Selenium(可能)不恰当。
您很可能需要执行以下操作之一来解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.