public class ReplaceInFile { public static void main(String[] args) throws IOException { String fileName = "file.txt"; String search = "31415"; String replace = "число ПИ"; Charset charset = StandardCharsets.UTF_8; Path path = Paths.get(fileName); Files.write(path, new String(Files.readAllBytes(path), charset).replace(search, replace) .getBytes(charset)); } } In this class, I am looking for a text grammar in a file by complete coincidence. How to make it so that after a full match, the program reads the string before the character ; ?
Sample search
File:
IP=123123; CONNECT=456456; DADADA dadada; DATA=321321; If I am looking for a CONNECT = then its value must be counted before the sign ; .
CONN, the result should beECT=456456? - vp_arth