簡體   English   中英

我將圖像文件保存在Java項目中以創建.jar的位置

[英]Where I keep my image files in java project to make .jar

我創建了一個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);

    }

}  

}

您無法從“ src / image2”訪問文件,因為jar中沒有文件夾。

像在另一個問題中一樣使用getClass().getResource() 將圖像添加到JAR Java

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM