Java: Changing strings in a file

I want to open files from different visual studio projects and replace some strings with a new one. The problem is, that code that i dont want to replace gets changed too. Am i using the wrong charset?Code from Notepad

public static void EditFile(File file)
    Charset charset = StandardCharsets.UTF_8;

    //Converting string to Path
    Path file_path = Paths.get(file.getParent() + "\" + file.getName());

    try {           
        String content = new String(Files.readAllBytes(file_path), charset);
        content = content.replaceAll("foo", "bar");

        Files.write(file_path, content.getBytes(charset));
    catch (IOException e) {