import java.io.*;

public class Example {
public static void main(String[] args) {
char a[] = "今天10点出发".toCharArray();
int n = 0;
try {
File out = new File("word.txt");
for (int i = 0; i < a.length; i++) {
a[i] = (char) (a[i] ^ 'R');
}
FileWriter fw = new FileWriter(out);
fw.write(a, 0, a.length);
fw.close();
FileReader fr = new FileReader(out);
char tom[] = new char[10];
System.out.println("加密后:");
while ((n = fr.read(tom, 0, 10)) != -1) {
String s = new String(tom, 0, n);
System.out.println(s);
}
fr.close();
fr = new FileReader(out);
System.out.println("明文:");
while ((n = fr.read(tom, 0, 10)) != -1) {
for (int j = 0; j < n; j++) {
tom[j] = (char) (tom[j] ^ 'R');
}
String str = new String(tom, 0, n);
System.out.println(str);
}

fr.close();
} catch (Exception e) {
e.printStackTrace();
}

}

}

Java_I/O输入输出_使用输入输出流读取文件,将一段文字加密后存入文件,然后读取,将加密前与后的文件输出

 

相关文章:

  • 2021-11-20
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2021-07-17
  • 2022-12-23
猜你喜欢
  • 2021-11-05
  • 2022-01-03
  • 2021-09-17
  • 2022-12-23
  • 2021-04-29
  • 2022-02-02
相关资源
相似解决方案