i need to write a program which will encrypt a string using a character mapping provided in a file. The input to your program will be a file which contains mapping for characters. For E.g. A D B R S H with this mapping if the string has an 'A' then it should be replaced by 'D' etc... I have to use java exception handling to handle any exceptions like "File not found","File format not correct", "No mapping Present" etc....
author and iconoclast
OK, so you've told us your assignment. Now you have to show us what you've done so far. If you haven't been able to start: reading in the data file would be a good first step!
As with all programming: take little steps. Write the code to open a file, make sure it compiles, test it. Then add code to read a line and print it out. Make sure it compiles, and then test it. Then write a loop to read all the lines, and test that. Take it one step at a time, and it will be easy.
You're storing the data using String objects as keys in the map, but you're trying to look it up using Character objects -- different kinds of objects, so they aren't interchangeable. Instead of get(s.charAt(i)), use get(String.valueOf(s.charAt(i))) .