![](/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.