java - 如何使用一种方法的文件返回到同一类的另一个方法中
问题描述
Step1:用户点击按钮文件被下载。
Step2:读取该pdf的内容。
预期:在下载之前删除文件,如果它已经存在
试过:
public File A() {
String userDir = System.getProperty("user.home")+"\\Downloads";
File file = new File(userDir+"\\PDFStatement.pdf");
return file;
}
public void clickxxxButton() {
try {
File f=pst.A();
if (f.exists()) // to delete the already existing file before downloading
{
f.delete();
}
}
catch (Exception e){
e.getMessage();
}
clickOn(xxxxButton);// here pdf file gets downloaded
}
public void verifyPDFContents() {
try {
//Loading an existing document
File file =pst.A();// here pst is the object of the same class where this method resides
PDDocument document = PDDocument.load(file);
//Instantiate PDFTextStripper class
PDFTextStripper pdfStripper = new PDFTextStripper();
//Retrieving text from PDF document
String text = pdfStripper.getText(document);
System.out.println(text);
//Closing the document
document.close();
file.delete()
}
catch (IOException e) {
e.printStackTrace();
}
}
我收到 pageobject 依赖注入错误。虽然如果我在 verifypdfcontent 中拥有所有内容(除了 delete )(比如声明和创建文件),它工作正常
解决方案
推荐阅读
- easeljs - how to move a line Shape object
- java - Java not allowed to call recursive method with generic type?
- powershell - PowerShell脚本将文件而不是子文件夹复制到SFTP并在完成后移动到子文件夹
- html - 在 HTML 中调整包含图标和文本的列表中的间距
- c# - Running .NET 2.0 4.0 machine without app.config?
- ruby - `initialize': 使用 Nokogiri 打开站点时没有这样的文件或目录@rb_sysopen
- javascript - 如何为某个 div(而不是整个页面)运行 queryCommandState?
- spring-boot - Caused by: java.net.SocketTimeoutException: Read timed out
- amazon-web-services - AWS ECS CodePipeline build error REPOSITORY_URI
- javascript - 如何使用 JavaScript 将元素设置为仅在 Wix 中显示一段时间?