Java image encryption resolve the issue

hare singh nayak

hare singh nayak

@hare-singh-nayak-WEmcz0 Oct 26, 2024
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
}
}

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • rahul69

    rahul69

    @rahul69-97fAOs Mar 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];
  • hare singh nayak

    hare singh nayak

    @hare-singh-nayak-WEmcz0 Mar 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