Originally Posted by
MrHatchi87
I need a little help, I have some depreciated code, and I have no idea how to change it to newer without rewriting the whole thing. any assistance is appreciated
import java.util.*;
import java.io.*;
public class OneLetterOff {
public static void main(String[] args) throws Exception {
DataInputStream input = new DataInputStream(System.in);
System.out.print("1.Encrypt a file\t2.Decrypt a file\n");
System.out.print("Enter your coice: ");
int n = Integer.parseInt(input.readLine());
System.out.print("Enter file name with out extension: ");
String file = input.readLine();
switch (n) {
case 1:
encrypt(file);
break;
case 2:
decrypt(file);
break;
default:
System.out.println("Invalid choice");
}
}
public static void encrypt(String file) throws Exception {
BufferedReader br = new BufferedReader(new FileReader(file + ".txt"));
PrintWriter ps = new PrintWriter(new FileOutputStream("Encrypt.txt"));
String line;
while ((line = br.readLine()) != null) {
for (int i = 0; i < line.length(); i++) {
Character c = line.charAt(i);
char ch = line.charAt(i);
if (c.isLetter(ch)) {
if (ch == 'z')
ch = 'a';
else if (ch == 'Z')
ch = 'A';
else
ch++;
}
ps.write("" + ch);
}
}
br.close();
ps.close();
System.out
.println("file encrypted successfully check the Encrypt.txt file");
}
public static void decrypt(String file) throws Exception {
BufferedReader br = new BufferedReader(new FileReader(file + ".txt"));
PrintWriter ps = new PrintWriter(new FileOutputStream("Decrypt.txt"));
String line;
while ((line = br.readLine()) != null) {
for (int i = 0; i < line.length(); i++) {
Character c = line.charAt(i);
char ch = line.charAt(i);
if (c.isLetter(ch)) {
if (ch == 'a')
ch = 'z';
else if (ch == 'A')
ch = 'Z';
else
ch--;
}
ps.write("" + ch);
}
}
br.close();
ps.close();
System.out
.println("file decrypted successfully check the Decrypt.txt file");
}
}
the bold items are the items that appear as depreciated, I don't recall what it recommends. Sorry, I'm at work now and can't access my laptop