I got a byte array string of a file and would like every byte to be taken minus 2 or something like that, and later to be taken plus 2. I wanted to do it like this:
byte buffer[] = new byte[(int) file.length()];
try {
in = new FileInputStream(file);
in.read(buffer);
for(int i = 0; i < buffer.length; i++){
buffer[i] = (byte) (buffer[i]-2); // and then later +2
}
}
But it doesn't work. First it changes the file like I want to, but later when I take the whole thing +2 it gives me something else strange.
So all together I want this:
- Get a byte array called
buffer
- Then change some values
- Change these values back
- Get the same files as before