0

Okay so let's say I read a file and obtain all its bytes, byte[].

byte[] fileBytes = whatever;

(Let's pretend whatever is me reading the bytes)

Now let's say I made a string out of it with the OS's default charset,

String s = new String(fileBytes, Charset.defaultCharset());

In my case the OS's default charset is windows-1252.

Right now because we read the file through the default charset, s.getBytes() is different from fileBytes.

How could we reverse the String s knowing the default charset back into the original fileBytes?

I appreciate all help, thanks! :)

Andre
  • 778
  • 1
  • 5
  • 23

1 Answers1

0

According to me, you can do it vice versa.

byte[] fileBytes = whatever;
String s = new String(fileBytes, Charset.defaultCharset());

You can reverse it by doing the following.

byte[] reversedFileBytes = s.getBytes(Charset.defaultCharset());
Gippy Aulakh
  • 104
  • 7