Suppose I have a properties file named features.properties
with some of its properties encrypted in byte array format.
e.g. color = [64, 14, 76, 92, 5, 114, 54, 31]
I want to read this property value in java.
If I use properties.getProperty("color")
, since return type
of getProperty()
is a String
, it returns me an address which I think is the base address of the byte array.
I should be using FileInputStream
to read it but do not know exactly how to use it. Please help!
with some of its properties encrypted in byte array format
I suspect you don't actually mean "encrypted" here. You're just representing the bytes as text - I don't see any encryption. If they really are encrypted as well, that's a separate step you'll need to take.
it returns me an address which I think is the base address of the byte array
No, it returns you the value as a string, e.g. "[64, 14, 76, 92, 5, 114, 54, 31]". Properties files have no direct support for binary data as far as I'm aware.
The simplest approach would be to change the format to just use base64 encoding or maybe hex for the string. There are plenty of options for converting base64/hex data from text to binary. (Search for questions on Stack Overflow about that.)
If you can't change the format, then you'll need to remove the leading and trailing square brackets, split the result by commas, trim each individual part ("64 " etc) and then parse that, e.g. with Byte.parseByte
.
See more on this question at Stackoverflow