发布网友 发布时间:2022-04-21 22:39
共2个回答
热心网友 时间:2023-11-11 13:29
import java.io.*;
class Encrypt{
private String pw;
private File fin;
private File fout;
public Encrypt(File fin,String pw,File fout) throws Exception{
if("".equals(pw)){
System.out.println("密码不能为空");
System.exit(1);
}
this.pw=pw;
if(!fin.exists()){
System.out.println("输入文件不存在");
System.exit(1);
}
this.fin=fin;
if(fout.exists()){
System.out.println("输出文件已存在");
System.exit(1);
}
this.fout=fout;
this.enc();
}
public void enc() throws Exception{
byte[] pass=pw.getBytes();
int length=pw.length();
int i=0;
InputStream in=new FileInputStream(fin);
OutputStream out=new FileOutputStream(fout);
int indata;
indata=in.read();
while(indata!=-1){
i++;
indata^=pass[i%length];
out.write(indata);
System.out.print((char)indata);
indata=in.read();
}
in.close();
out.close();
}
}
public class EncryptFile{
public static void main(String args[]) throws Exception{
if(args.length!=3){
System.out.println("参数错误:参数格式应为: input_file password output_file");
System.exit(1);
}
File fin=new File(args[0]);
File fout=new File(args[2]);
new Encrypt(fin,args[1],fout);
}
}
没完全按照你的要求 自己再改改吧 ~~~~~~~~~
热心网友 时间:2023-11-11 13:29
加入try {}catch语句