CrazyEngineers
  • Java image encryption resolve the issue

    Updated: Oct 26, 2024
    Views: 1.3K
    hay guys this code is written by me for image encryption the data is written in file but not preview.....
    help it's urgent.
    thanks in advance.

    package binaryfilehandling;
    import java.io.FileNotFoundException;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;

    /**
    *
    * @author WLAN_04
    */
    public class Main {
    /**
    * #-Link-Snipped-# args the command line arguments
    */
    public static void main(String[] args) {
    String strSourceFile="C://hare//Sunset.jpg";
    String strDestinationFile="C://hare//aaa.jpg";
    String a;
    int c;
    try
    {
    //create FileInputStream object for source file
    FileInputStream fin = new FileInputStream(strSourceFile);
    //create FileOutputStream object for destination file
    FileOutputStream fout = new FileOutputStream(strDestinationFile);
    byte[] b = new byte[10];
    byte[] b1 = new byte[10];
    int noOfBytes = 0;
    System.out.println("Copying file using streams");
    //read bytes from source file and write to destination file
    while( (noOfBytes = fin.read(b)) != -1 )
    {
    System.out.println(b.length);
    int j=0;
    for(int i=b.length-1;i>=0;i--){
    b1[j]=b;
    // System.out.println(b1);
    //System.out.println(b);
    j++;
    }

    fout.write(b1, 0 , noOfBytes);


    }

    System.out.println("File copied!");
    //close the streams
    fin.close();
    fout.close();
    }
    catch(FileNotFoundException fnf)
    {
    System.out.println("Specified file not found :" + fnf);
    }
    catch(IOException ioe)
    {
    System.out.println("Error while copying file :" + ioe);
    }

    // TODO code application logic here
    }
    }
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • rahul69

    MemberMar 5, 2013

    Could u tell in detail which preview are you talking about, the code seems fine, but I think, in line:
    for(int i=b.length-1;i>=0;i--){
    b1[j]=b;
    
    It should be b1[j]=b[j];
    Are you sure? This action cannot be undone.
    Cancel
  • hare singh nayak

    MemberMar 6, 2013

    rahul69
    Could u tell in detail which preview are you talking about, the code seems fine, but I think, in line:
    for(int i=b.length-1;i>=0;i--){
    b1[j]=b;
    
    It should be b1[j]=b[j];


    yes you are are right

    It should be b1[j]=b[j];

    but still
    i am not able to preview the encrypted image
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register