[英]Read File (not string) from Websphere MQ and save in to local drive
我能夠與MQ連接並閱讀消息。 但是在這里,MQ的文件輸入不是字符串(壓縮文件是某種.eff擴展名),我需要從MQ讀取並寫入文件系統目錄。
我已經完成了以下代碼,並且可以將字符串(不確定)寫入名為Myfile.eff的文件中。 但是,當我提取此文件時,它顯示錯誤“無法打開文件“ Myfile.eff”作為存檔”。 我可以看到文件大小為643KB。
public string GetMessageOffQueue()
{
string message = "";
queue = queueManager.AccessQueue(queueName, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
queueMessage = new MQMessage();
queueMessage.Format = MQC.MQFMT_STRING;
try
{
queue.Get(queueMessage);
message = queueMessage.ReadString(queueMessage.MessageLength);
FileStream fs = new FileStream("Myfile.eff"e, FileMode.Create);
// Create the writer for data.
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(message);
fs.Close();
bw.Close();
using (StreamWriter myStream = new StreamWriter( "Myfile2.eff", true))
{
myStream.Write(message);
}
}
catch (MQException MQExp)
{
Console.WriteLine("MQQueue::Get ended with " + MQExp.Message);
}
return message;
}
如何將確切的文件讀寫到目錄中?
提前致謝。
http://www-01.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.ref.dev.doc/q111220_.htm
ReadString為您將數據轉換為Unicode-不是您想要的
嘗試使用ReadBytes,它給出一個字節數組
我可以設法讀取並保存到本地目錄。 解決方法如下。
MQGetMessageOptions mqGetMsgOpts =新的MQGetMessageOptions(); mqGetMsgOpts.Options = MQC.MQGMO_BROWSE_FIRST;
MQMessage msg = new MQMessage();
queue.Get(msg, mqGetMsgOpts);
MQGetMessageOptions mqGetNextMsgOpts = new MQGetMessageOptions();
mqGetNextMsgOpts.Options = MQC.MQGMO_BROWSE_NEXT;
try
{
while (true)
{
string messageText = msg.ReadString(msg.MessageLength);
//Write to File
byte[] byteConent = new byte[msg.MessageLength];
msg.ReadFully(ref byteConent, 0, msg.MessageLength);
File.WriteAllBytes("sample.eff", byteConent);
//
msg = new MQMessage();
queue.Get(msg, mqGetNextMsgOpts);
}
}
catch (MQException ex)
{
// Handle it
}
謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.