I am trying to read a file line by line and save it to a byte array, but for some reason String.getBytes() throws a Nullpointer Exception.
What am I doing wrong?
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
byte[][] bytes = null;
try {
String data;
int i = 0;
while((data = br.readLine()) != null) {
bytes[i] = data.getBytes(); // THROWS A NULLPOINTER EXCEPTION HERE
i++;
}
System.out.println(bytes.length);
} catch (IOException e)
e.printStackTrace();
}
}