我这里有一些基本代码来加密文本文件。我想将文本文件中的每个字符加一,将来可能会有所不同。但我不知道如何将数组“arr”设置为 char 值以进行递增。任何想法都会有所帮助!
import java.io.*;
public class EncryptionMain {
public static void main(String args[]) {
File file = new File("c:\\Visual Basic Sign in\\password.txt");
StringBuilder contents = new StringBuilder();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String text = null;
// repeat until all lines is read
while ((text = reader.readLine()) != null) {
contents.append(text)
.append(System.getProperty(
"line.separator"));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
int first = 0, second = 1;
for (int i = 0; i < contents.length(); i++)
{
char[] arr = new char[7];
contents.getChars(first, second, arr, 0); // get chars 0,1 to get 1st char
char ch = arr.toChar();
if (ch >= 'A' && ch < 'Z') ch++;
else if (ch == 'Z') ch = 'A';
else if (ch >= 'a' && ch < 'z') ch++;
else if (ch == 'z') ch = 'z';
System.out.println(arr);
first++;
second++;
}
}
}