代码如下:
import java.io.*;
public class T {
public static void main(String[] args) {
File srcFile=new File("data.txt");
File desFile=new File("crpData.txt");
try {
FileInputStream fis=new FileInputStream(srcFile);
FileOutputStream fos=new FileOutputStream(desFile);
while(true){
int i=fis.read();
if(i==-1)
break;
if((i>64&&i<=88)||(i>96&&i<=120)){
i=i+3;
}
if((i>88&&i<91)||(i>120&&i<123)){
i=i-23;
}
fos.write(i);
}
fos.close();
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
运行结果 srcData中内容如下:
Fklqhvh Qdph:Jxrtldqj Ckdqj
Hqjolvk Qdph: Hggb Ckdqj
Vh{: Pdoh
Eruq: 6/12/82
Xqlbhuvlwb: Ehlmlqj Xqlbhuvlwb
Pdmru: Pdunhwlqj
Dgguhvv: 328#, Ehlmlqj Xqlbhuvlwb
Whohskrqh: 1398****451
Hpdlo: ****
有问题追问,满意请采纳!
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Encryption {
public static void main(String[] args) {
File in = new File("D:/up/data.txt");
try {
FileInputStream fis = new FileInputStream(in);
byte[] bytes = new byte[1000];
fis.read(bytes);
bytes = encrypt(bytes);
File out = new File("D:/up/cypData.txt");
FileOutputStream fos = new FileOutputStream(out);
fos.write(bytes);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static byte[] encrypt(byte[] bytes){
byte b;
for(int i = 0 ; i < bytes.length; i++){
b = bytes[i];
if(b>='a' && b <= 'z'){
b += 3;
if(b >'z'){
b -= 26;
}
bytes[i] = b;
}
if(b>='A' && b <= 'Z'){
b += 3;
if(b > 'Z'){
b -= 26;
}
bytes[i] = b;
}
}
return bytes;
}
}