公共類機密示例{
公共靜態void main(String[] args) {
File File one = new File(" d:/hello . txt "),File two = new File(" d:/hello . secret ");
char b[]= new char[100];
嘗試
{
FileReader in = new FileReader(file one);
FileWriter out = new FileWriter(file two);
int n =-1;
while((n=in.read(b))!=-1)
{
for(int I = 0;我& ltn;i++)
{
b[i]=(char)(b[i]^'a');
}
out . write(b);
//寫文件
}
out . close();//關閉
in = new file reader(file two);
System.out.println("加密文件內容:");
while((n=in.read(b))!=-1)
{
String str =新字符串(b,0,n);
system . out . println(str);
}
in = new file reader(file two);
System.out.println("解密文件內容:");
while((n=in.read(b))!=-1)
{
for(int I = 0;我& ltn;i++)
{
b[i]=(char)(b[i]^'a');
}
System.out.printf(new String(b,0,n));
}
in . close();//在中關閉
}
捕捉(IOException e)
{
system . out . println(e);
}
}
}