publicvoidFileEn(StringfileReadPath,StringfileWritePath,Stringpassword,intlength){FilefileRead=newFile(fileReadPath);FilefileWrite=newFile(fileWritePath);if(!fileRead.exi...
public void FileEn(String fileReadPath,String fileWritePath,String password,int length){
File fileRead=new File(fileReadPath);
File fileWrite=new File(fileWritePath);
if(!fileRead.exists())
{
System.out.println("文件不存在");
System.exit(0);
}
if(!fileWrite.exists()){
System.out.println("创建文件");
try {
fileWrite.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/* 下面怎么写try catch */
FileInputStream fins=new FileInputStream(fileRead);
FileOutputStream fous=new FileOutputStream(fileWrite);
byte[] data=new byte[fins.available()]; //读取图片的整个长度
int HeadLength=623; //jpg头部信息的长度
byte[] head=new byte[HeadLength];
byte[] temp=new byte[16];//由于AES是十六的倍数才能加密,不够的话会自动填充字段,即PKCS5Padding处理
byte[] end;
int len;
int readLen;
len=fins.read(data);
fins.close();
for(int i=0;i
head[i]=data[i];//读取头部信息
fous.write(head);
readLen=HeadLength;//表示当前读取的位置
while((readLen+16)
for(int j=0;j<16;j++)//每16个字节读取
temp[j]=data[readLen+j];
fous.write(encrypt(temp, password, length));//进行加密并且写入
readLen+=16;//当前读取位置+16
}
end=new byte[len-readLen];
for(int k=0;k
end[k]=data[readLen+k];
fous.write(end);
//对于最后小于16的字段不加直接写入,是为了避免PKCS5Padding
fous.close();
}
下面那里怎么写try catch 一直报错啊,万分感谢!!!
展开