My code(pasted below) basically replaces A, B, C with C, P, Q.
My new requirement is, I am going to create a file and then it has to replace the A, B, C of file content with C, P, Q. How do I do it?
for example: let's say the name of the file is the filename.txt.So what changes do I have to make to existing code, please help
public class replacefunction1 { public static void main(String[] args) { // TODO Auto-generated method stub File file = new File("filename.txt"); HashMap<Character, Character> replacements = new HashMap<>(); replacements.put('a', 'c'); replacements.put('b', 'p'); replacements.put('c', 'q'); String input = "abcd"; StringBuilder output = new StringBuilder(); for (Character c : input.toCharArray()) { output.append(replacements.getOrDefault(c, c)); } System.out.println(output.toString()); }