Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Encryption

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
i urgently need help....

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
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shelly Biswal
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote the code everyting wrks fine except line /*1*/ - the output is always null dont know why.. pls explain



ReadCharacterMapping.java

 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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))) .
 
BWA HA HA HA HA HA HA! Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!