Q:

append bytes to string in java

I have to deal with ascii structured file, I need to put these two constant bytes to the end of every line so that I can respect the file structure that was gave me:
private final static int ENDRECORD = 0x0d;
private final static int ENDLINE = 0x0a;

I don't know if it's the classic "\n", is there a way I can put these two variables at the end of a string?
Like:

String line = line + ENDRECORD + ENDLINE; //I now this is wrong

A:

You're close.  It's '\r' and '\n'.
System.out.println((int) '\r');
System.out.println((int) '\n');

Output:
13
10

which is 0x0d and 0x0a, respectively.  Use chars:
private final static char ENDRECORD = '\r';
private final static char ENDLINE = '\n';

and
String line = line + ENDRECORD + ENDLINE;

Additionally, you can use StringBuilder for efficiency instead of concatenation.  It's not necessary to get this to work, but it's standard to use it for building strings instead of concatenation with +.

