Hex Value from Properties file : JAVA

In my Java Program, I need a byte array from a Hex String. So I do the following: byte[] key=HexUtils.convert("0AA387ED291F6D90");

This converts the Hex String into a byte array as follows: Output: Byte Array: key:[10, -93, -121, -19, 41, 31, 109, -112]

Now, I want to move the Hex String into the properties file. But I am not able to do so.

Try 1: Properties file ====> key=0AA387ED291F6D90 Java Program ====> byte[] key = HexUtils.convert(prop.getProperty("key"));

This gives error: BAD HEXADECIMAL DIGIT

Try 2: Properties file ====> key=\u000A\u00A3\u0087\u00ED\u0029\u001F\u006D\u0090 Java Program ====> byte[] key = HexUtils.convert(prop.getProperty("key"));

Output: key:[10, -93, 63, -19, 41, 31, 109, 63]

If you notice, 2 bytes are different than the Expected. Hex 87 and Hex 90. Both are converted to 63. Whereas I am expecting -121 and -112 respectively.

Can somebody please help me as to how do I do this conversion. I hope I am clear!

Angad

Answers


If using the \uxxxx codes, you're using UNICODE escape sequences. \u0090 is not going to end up being interpreted as String "90", it's gonna end up as a single character that corresponds to code unit 0090 in the UTF-16 encoding.

Your first approach should work. I suggest you try System.out.println(prop.getProperty("key")); or some other form of output and check if there's leading or trailing white space, some character you didn't expect or null. The latter would mean the property for "key" isn't found.


Need Your Help

Meteor using variable from template.rendered into template.event

javascript jquery meteor

I have this menu from jQuery, referenced by "template.rendered". This is so "var meny = Meny.create({})" runs perfectly. However, in my "template.events", I want it to close the menu and then scr...

jquery validation engine always getting same response on ajax validation

jquery ajax coldfusion jquery-validation-engine

I have jquery validate engine validating a form. For example the code to check mobileno is already exists in database :

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.