Author |
Message
|
nzr1949 |
Posted: Fri Jul 22, 2005 12:48 am Post subject: Question about readLine |
|
|
Novice
Joined: 16 Nov 2004 Posts: 15
|
Hi,
I've placed a text file onto a queue and would like to read the contents of the file back off the queue and then write them to a text file. I'm using the readLine() method to read one line of the message at a time. The problem I'm having is that I can't detect when the end of the message has been reached. Portion of code is below:
Code: |
MQMessage m = new MQMessage();
m.format = MQC.MQFMT_NONE;
MQMessage msg = new MQMessage();
MQGetMessageOptions ops = new MQGetMessageOptions();
ops.options = MQC.MQGMO_BROWSE_FIRST;
msg.clearMessage();
msg.correlationId = MQC.MQCI_NONE;
msg.messageId = MQC.MQMI_NONE;
// read the message without removing it
this.myQueue.get(msg, ops);
String line = "";
while (line = msg.readLine()) != null)
{
System.out.println(line);
}
|
When this code runs and reaches the while loop it becomes infinite and never ends, it prints the contents of the text file correctly but as soon as it reaches the end of the text file is starts printing empty strings. I have consulted the MQ Java manual and it doesn't state what value the readLine() method returns when it has reached the end of a text file. Surely it is null as I have it in the code above?
Thanks,
Ramsey |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Jul 22, 2005 3:40 am Post subject: Re: Question about readLine |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
nzr1949 wrote: |
while (line = msg.readLine()) != null) |
Your parentheses are not right. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
nzr1949 |
Posted: Fri Jul 22, 2005 7:44 am Post subject: |
|
|
Novice
Joined: 16 Nov 2004 Posts: 15
|
Sorry, that was a typo, it should read:
Code: |
while ((line = msg.readLine()) != null)
|
I'm still stumped, how do you detect the last line in the message? |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Jul 22, 2005 7:52 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I'm going to guess that your message doesn't end with any of the terminators mentioned in
Using Java wrote: |
readLine
public String readLine() throws IOException;
Reads a line of text from the message. Converts from the codeset identified in characterSet, and then reads in a line that has been terminated by \n, \r, \r\n, EOF or the end of a UTF string. |
_________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
amitaborker |
Posted: Wed Jul 27, 2005 4:12 am Post subject: Try this |
|
|
Newbie
Joined: 27 Jul 2005 Posts: 1 Location: Bangalore
|
while (msgToRead.getDataLength()>0)
{
System.out.println(msgToRead.readLine());
} |
|
Back to top |
|
 |
nzr1949 |
Posted: Wed Jul 27, 2005 4:31 am Post subject: |
|
|
Novice
Joined: 16 Nov 2004 Posts: 15
|
That works like a charm.
Thanks! |
|
Back to top |
|
 |
|