[英]File exists but when I perform operation on that file, system shows FileNotFoundException. Works when file is in dir where source code is
public void decrypt() throws Exception
{
//opening streams
//Error is in the line below When i try to read file from directory
//other than the one which has .java and .class files.
FileInputStream fis1 =new FileInputStream(file);
File dir=new File("C:/Crypt-R/Decrypted");
dir.mkdirs();
file=new File(dir,file.getName() +".dec");
FileOutputStream fos1 =new FileOutputStream(file);
//generating same key
byte k[] = keyRecv.getBytes();
SecretKeySpec key = new SecretKeySpec(k,"AES");
//creating and initialising cipher and cipher streams
Cipher decrypt = Cipher.getInstance(algorithm);
decrypt.init(Cipher.DECRYPT_MODE, key);
CipherInputStream cin=new CipherInputStream(fis1, decrypt);
byte[] buf = new byte[1024];
int read=0;
while((read=cin.read(buf))!=-1) //reading encrypted data from file
{
fos1.write(buf,0,read); //writing decrypted data to file
}
//closing streams
cin.close();
fos1.flush();
fos1.close();
JOptionPane.showMessageDialog (null,
"File Decrypted",
"Success..!!",
JOptionPane.INFORMATION_MESSAGE);
}
有連接到該程序的文本編輯器,文件被顯示在編輯器中,但是當我試圖解密它,它不會在我的源代碼保持該目錄存在,那么就說明文件中未發現異常。 你能幫我這個忙嗎?
您需要檢查以下內容
1)確保您提到的位置確實存在文件名檢查獲取FileNotFoundException的原因
2)然后,您必須提及路徑“ C:\\\\ Users \\ ...”。 確保您使用正確的方式在Windows系統上提及文件名
3)您必須再次類似地檢查FileOutputStream。
您需要用
File.separator
其將持有的價值/
, :
或\\\\
取決於哪個平台上。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.