1

I have a csv string to bytes and i want to convert it in java byte array. Can anyone help me.

csv string

167, 27, 32, 195

The byte array should be like this

byte[0] should give me 167
byte[1] should give me 27
byte[2] should give me 32
byte[3] should give me 195
AndroidLearner
  • 1,360
  • 7
  • 24
  • 40

1 Answers1

1

You can use an array of characters. The char type is intended to represent characters in Java.

String csv = "167, 27, 32, 195";
String[] numbers = csv.split(", ");
char[] chars = new char[numbers.length];
for (int i = 0; i < numbers.length; i++)
    chars[i] = (char)Integer.parseInt(numbers[i]);

This method assumes that the numbers in the CSV file are Unicode code points of the characters.

Jirka Hanika
  • 12,963
  • 3
  • 42
  • 70