Reputation: 804
It is a very strange question(at least for me), but I've found some strange behavior of encoding in Java. For example you have some set of bytes. Then you interpret this bytes as string in some encoding. Than you get bytes of this string and save it to some another file. I think that encoding is just specified way to interpret bytes as string. But in this way bytes must be the same in both files, but they didn't.
This is sample code instance:
FileInputStream inputStream = new FileInputStream(new File("firstFile"));
byte[] arr = new byte[50000];
int l = inputStream.read(arr,0,50000);
arr = Arrays.copyOfRange(arr,0, l);
BASE64Encoder encoder = new BASE64Encoder();
String st = encoder.encode(arr);
FileOutputStream outputStream = new FileOutputStream(new File("secondFile"));
outputStream.write(st.getBytes(), 0, st.getBytes().length);
inputStream.close();
outputStream.close();
Upvotes: 0
Views: 148
Reputation: 269627
Let's say the first file contains one byte, 0x00.
The Base-64 encoding of that byte will be the String
, "AA=="
.
When you call getBytes()
on that string, you'll get 0x41, 0x41, 0x3D, 0x3D—one byte for each character in the string.
Those are the bytes written to the second file.
Upvotes: 1