i try to write String to file only if String not exist, this is my code
File rule_file = new File("test_rules.rules");
Scanner scanner = new Scanner(rule_file);
PrintWriter writer = new PrintWriter(new FileWriter(rule_file,true));
while (scanner.hasNextLine())
{
String lineFromFile = scanner.nextLine();
if(!rule_write.equals(lineFromFile))
{
if(unique.get(nilai_besar).getCount()>10)
{
writer.write(rule_write);
writer.close();
break;
}
}
}
but, the program keep write String to file even the String already exist in file. Please help, thanks...