java code for replacing the values in the txt file

import java.io.*;
import java.nio.file.*;
import java.util.*;

public class FileModifier {

    public static void main(String[] args) {
        String folderPath = "path/to/your/folder"; // Set the folder path
        String filenameToRead = "fileToRead.txt"; // The file to read and modify
        String filenameWithValues = "valuesFile.txt"; // The file with values to replace

        Path filePathToRead = Paths.get(folderPath, filenameToRead);
        Path filePathWithValues = Paths.get(folderPath, filenameWithValues);

        try {
            // Read the file with values to replace
            List<String> valuesToReplace = Files.readAllLines(filePathWithValues);
            Set<String> uniqueValues = new HashSet<>(valuesToReplace);

            // Read the content of the file to modify
            String content = new String(Files.readAllBytes(filePathToRead));

            // Replace values
            for (String value : uniqueValues) {
                content = content.replaceAll(value, "111111");
            }

            // Write the modified content back to the file
            Files.write(filePathToRead, content.getBytes());
            System.out.println("File modified successfully!");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
//this is final one
import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.stream.*;

public class FileModifier {

    public static void main(String[] args) {
        String folderPath = "path/to/your/folder"; // Set the folder path
        String filenameWithValues = "valuesFile.txt"; // The file with values to replace

        Path folder = Paths.get(folderPath);
        Path filePathWithValues = folder.resolve(filenameWithValues);

        try {
            // Read the file with values to replace
            List<String> lines = Files.readAllLines(filePathWithValues);
            Map<String, String> replaceMap = new HashMap<>();

            for (String line : lines) {
                String[] parts = line.split("\\s+"); // Assuming values are separated by spaces
                if (parts.length >= 2) {
                    replaceMap.put(parts[0], parts[1]);
                }
            }

            // Process each text file in the folder
            try (Stream<Path> paths = Files.walk(folder)) {
                paths.filter(Files::isRegularFile)
                     .filter(path -> !path.equals(filePathWithValues)) // Exclude the valuesFile.txt
                     .forEach(filePathToRead -> modifyFile(filePathToRead, replaceMap));
            }

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

    private static void modifyFile(Path filePath, Map<String, String> replaceMap) {
        try {
            // Read the content of the file to modify
            String content = new String(Files.readAllBytes(filePath));

            // Replace values based on the map
            for (Map.Entry<String, String> entry : replaceMap.entrySet()) {
                content = content.replaceAll(entry.getKey(), entry.getValue());
            }

            // Write the modified content back to the file
            Files.write(filePath, content.getBytes());
            System.out.println("File " + filePath.getFileName() + " modified successfully!");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
import java.io.*;
import java.nio.file.*;
import java.util.*;

public class FileModifier {

    public static void main(String[] args) {
        String folderPath = "path/to/your/folder"; // Set the folder path
        String filenameToRead = "fileToRead.txt"; // The file to read and modify
        String filenameWithValues = "valuesFile.txt"; // The file with values to replace

        Path filePathToRead = Paths.get(folderPath, filenameToRead);
        Path filePathWithValues = Paths.get(folderPath, filenameWithValues);

        try {
            // Read the file with values to replace
            List<String> lines = Files.readAllLines(filePathWithValues);
            Map<String, String> replaceMap = new HashMap<>();

            for (String line : lines) {
                String[] parts = line.split("\\s+"); // Assuming values are separated by spaces
                if (parts.length >= 2) {
                    replaceMap.put(parts[0], parts[1]);
                }
            }

            // Read the content of the file to modify
            String content = new String(Files.readAllBytes(filePathToRead));

            // Replace values based on the map
            for (Map.Entry<String, String> entry : replaceMap.entrySet()) {
                content = content.replaceAll(entry.getKey(), entry.getValue());
            }

            // Write the modified content back to the file
            Files.write(filePathToRead, content.getBytes());
            System.out.println("File modified successfully!");

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