Привет Я пытаюсь написать код, который будет читать файл с стихотворением. Затем он изменит первое «вы» в каждой строке с «мы». Я пытаюсь использовать replaceFirst(), replace(), replaceAll(); однако ни один из них не работал над заменой чего-либо.Java String.replaceFirst() issue
import java.io.*;
import java.util.Scanner;//imports
public class TextEditorTester
{
private static boolean line_change;
public static void main(String[] args) throws FileNotFoundException
{
String line = "";
File inFile = new File("OldPoem.txt");
Scanner in = new Scanner(inFile);
PrintWriter out = new PrintWriter("NewPoem.txt");
while(in.hasNextLine()){
line = in.nextLine();
line.replace("you", "we");
out.println(line);
}
out.close();
File newFile = new File("NewPoem.txt");
Scanner newOne = new Scanner(newFile);
System.out.println(newOne.nextLine());
System.out.println("Expected: Have we ever tried to enter the long black branches of other lives");
}
}