Possibly a more Java way of doing it is in java.util.Arrays, look at the copyOf methods.
Michael Whapples On 13/12/10 20:57, Sina Bahram wrote:
Yes, there is a System.arrayCopy Take care, Sina -----Original Message----- From: brailleblaster-bounce@xxxxxxxxxxxxx [mailto:brailleblaster-bounce@xxxxxxxxxxxxx] On Behalf Of qubit Sent: Monday, December 13, 2010 3:53 PM To: brailleblaster@xxxxxxxxxxxxx Subject: [brailleblaster] Re: java Byte arrays and string literals Ah, hi Sina -- I used streams because that is what was returned by the Process method to connect up to the stderr, stdout and stdin of the child process. If I had my druthers, I would not have used streams. By the way, I am just getting back from a day away from my laptop and am wondering the following: Is there a strncpy() equivalent for copying byte arrays in java? I don't know what takes longer: writing the loop myself or wading through the docs. Thanx. --le ----- Original Message ----- From: "Sina Bahram"<sbahram@xxxxxxxxx> To:<brailleblaster@xxxxxxxxxxxxx> Sent: Saturday, December 11, 2010 10:05 PM Subject: [brailleblaster] Re: java Byte arrays and string literals Why are you using streams in the first place? Take a step back and examine the problem here. Can't this be simply accomplished by giving those things an object? Barring that ... Giving them the whole stream, and letting them pump in/out what they need? Take care, Sina -----Original Message----- From: brailleblaster-bounce@xxxxxxxxxxxxx [mailto:brailleblaster-bounce@xxxxxxxxxxxxx] On Behalf Of qubit Sent: Saturday, December 11, 2010 9:38 PM To: brailleblaster@xxxxxxxxxxxxx Subject: [brailleblaster] java Byte arrays and string literals Hi -- ok, Sina, on the other list you said I was taking the wrong approach. That is altogether possible as I am pushing up against a few awkward bits of code that should not be necessary, IMO, and I think you agree. The awkwardness I am experiencing comes when a method needs to call another method from another package, not written by me. My class is now compiling, and I think should work, but I am having problems with the test.main method. What I'm wondering is either how to initialize this Byte array with the characters of "This is a test.". javac keeps barfing on that. I pass this byte array to a method in my class, as input to the OutputStream I am writing to. The reason I am passing this is because the OutputStream/InputStream classes and their descendants contain the following definitions respectively: void write(Byte[] buf, int startPos, int len ) int read(Byte[] buf, int startPos, len); Comments? TIA --le