[英]JAva: why isn't anything being written to my txt file?
public static void getMembers(WebDriver driver, String outname){
FileWriter outFile = null;
try {
outFile = new FileWriter(new File("myfile.txt"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//continue from 900
for(int i=1;i<=5070;i++){
driver.get("/username&page="+i);
List<WebElement> links = driver.findElements(By.xpath("/html/body/div[2]/div/div/form/table[2]/tbody/tr/td/a"));
for(WebElement link : links){
if (link.getText() == ""){
}else{
try {
outFile.write(link.getText() + "\n");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(link.getText());
}
}
}
}
的System.out.println(link.getText()); 吐出適當的字符串......但是myfile.txt是空的!
你還沒有關閉outFile
:
outFile.close();
關閉文件會刷新任何緩沖的輸出並將其寫入磁盤上的文件。 完成將所有內容寫入文件后執行此操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.