Java image encryption resolve the issue

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

  • rahul69
    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];
  • hare singh nayak
    hare singh nayak
    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

You are reading an archived discussion.

Related Posts

hi..everyone...i m participating in sae baja for the first time...i m designing the transmission..ive selected mahindra alpha transmission....i want to know whether it is good or do i need to...
Hi, I am Prasanna. I am getting my BE (ECE) degree this year. I wish to appear for C-DAC CET. Hence please tell me that where I can get the...
I'm planning to make a code editor, as part of my academic project. It uses a web interface that displays to the other team members what i'm coding(lively). It will...
I am piyush, final year student of computer engineering from pune university, India. Yet I am not placed in any company 😭 . I am confused about what to do...
hello, how are u all? I'm ur new friend. I would like to know about the problems of electrical and electronic engineering.