我创建了一个java项目,通过使用netbeans单击问题和答案按钮来显示问题和答案。我将这些图像放在“src”文件夹中。也就是那些加密后放置的图像。 完成我的项目后,我制作.jar文件。当我运行.jar文件时,它说 “java.io.filenotfoundexception:”file_path“(系统找不到指定的路径)”。 我怎样才能解决这个问题。 提前谢谢。
public static void main(String[]args){
String imageName[] ={"A01","A02","A03","B01","B02","B03"};
String imageNameEncrypy[] ={"A001","A002","A003","B001","B002","B003"};
for(int i=0;i<imageName.length;i++){
try{
//FileInputStream file;
FileInputStream file = new FileInputStream("src/image2/"+imageName[i]+".jpg");
FileOutputStream output = new FileOutputStream("src/image2/"+imageNameEncrypy[i]+".jpg");
byte j[]="NiTh5252".getBytes();
SecretKeySpec kye = new SecretKeySpec(j,"DES");
System.out.println(kye);
Cipher enc = Cipher.getInstance("DES");
enc.init(Cipher.ENCRYPT_MODE,kye);
CipherOutputStream cos = new CipherOutputStream(output, enc);
byte[] buf = new byte[1024];
int read;
while((read=file.read(buf))!=-1){
cos.write(buf,0,read);
}
file.close();
output.flush();
cos.close();
JOptionPane.showMessageDialog(null,"Suscess");
}catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
}
解密代码
int k=i;
String questionImage[]={"","B001","B002","B003"};
String questionDecryptImageName=questionImage[k];
String afterDrcryptName[]={"A.jpg","B.jpg","C.jpg","D.jpg"};
try{
FileInputStream file = new FileInputStream("src/learning/dvd/Temp2/"+questionDecryptImageName+".jpg");
FileOutputStream output = new FileOutputStream("src/learning/dvd/Temp2/"+afterDrcryptName[k]);
byte j[]="NiTh5252".getBytes();
SecretKeySpec kye = new SecretKeySpec(j,"DES");
System.out.println(kye);
Cipher enc = Cipher.getInstance("DES");
enc.init(Cipher.DECRYPT_MODE,kye);
CipherOutputStream cos = new CipherOutputStream(output, enc);
byte[] buf = new byte[1024];
int read;
while((read=file.read(buf))!=-1){
cos.write(buf,0,read);
}
file.close();
cos.close();
output.flush();
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
}
答案 0 :(得分:0)