长时间没用这个,忽然用起的时候,忘了怎么写,记录下
public static void main(String[] args) throws IOException {
List<String> lines=null;
try{
lines=FileUtils.readLines(new File(file),Charsets.toCharset("utf-8"));
System.out.println("请输入");
Scanner scanner= new Scanner(System.in);
while (true){
String s =scanner.nextLine();
if ("ok".equals(s)){
break;
}
if (!lines.contains(s)){
System.out.println("添加 "+s);
lines.add(s);
}
System.out.println("请输入");
}
}finally {
if (lines!=null)
FileUtils.writeLines(new File(file),"utf-8",lines,false);
System.out.println("结束");
}