gpt4 book ai didi

java - 在文本文档中查找以 notification 开头的行并将其删除

转载 作者:行者123 更新时间:2023-12-01 22:17:45 24 4
gpt4 key购买 nike

我正在尝试从测试文档中删除以 public 开头的行。我已尝试以下操作,但 public 行未被删除。我该如何修复它?我感谢任何帮助。

简单:

In less than a week,
public face of FIFA

has gone from something resembling

an old-style Communist Party rally
to what looks more like a scene from

代码:

try (PrintWriter writer = new PrintWriter("D:\\hl_sv\\" + newName);

Scanner scanner = new Scanner(file)) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (!line.equals("public")) {

writer.println(line);
writer.flush();
}


}
} catch (Exception e) {
e.printStackTrace();
}

最佳答案

您需要使用String#startsWith(String str):

if (!line.startsWith("public")) {

equals 检查整行是否等于public

关于java - 在文本文档中查找以 notification 开头的行并将其删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30652232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com