简体   繁体   English

从Websphere MQ读取文件(非字符串)并保存到本地驱动器

[英]Read File (not string) from Websphere MQ and save in to local drive

I am able to connect with MQ and read the message. 我能够与MQ连接并阅读消息。 But here, the MQ has a file input not a string ( zipped file some kind of .eff extension) and i need to read from MQ and write in to the filesystem directory. 但是在这里,MQ的文件输入不是字符串(压缩文件是某种.eff扩展名),我需要从MQ读取并写入文件系统目录。

I have done the below code and i could write the string (not sure) in to file named Myfile.eff . 我已经完成了以下代码,并且可以将字符串(不确定)写入名为Myfile.eff的文件中。 But when i am extracting this, it shows error " Cannot Open File "Myfile.eff" as archive". 但是,当我提取此文件时,它显示错误“无法打开文件“ Myfile.eff”作为存档”。 I can see the file size is 643KB. 我可以看到文件大小为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;
        }

How can i read and write the exact file in to my directory ? 如何将确切的文件读写到目录中?

Thanks in advance. 提前致谢。

http://www-01.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.ref.dev.doc/q111220_.htm http://www-01.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.ref.dev.doc/q111220_.htm

ReadString converts the data into Unicode for you - not what you want ReadString为您将数据转换为Unicode-不是您想要的

Try using ReadBytes, which gives a byte array 尝试使用ReadBytes,它给出一个字节数组

I could manage to read and save in to local directory. 我可以设法读取并保存到本地目录。 The solution is as below; 解决方法如下。

MQGetMessageOptions mqGetMsgOpts = new MQGetMessageOptions(); MQGetMessageOptions mqGetMsgOpts =新的MQGetMessageOptions(); mqGetMsgOpts.Options = MQC.MQGMO_BROWSE_FIRST; 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
            }

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM