2014-11-03 4 views
0

MQ와 연결하여 메시지를 읽을 수 있습니다. 하지만 MQ에는 문자열이 아닌 파일 입력이 있고 (확장명이 .eff 인 압축 파일) MQ에서 읽고 파일 시스템 디렉토리에 쓸 필요가 있습니다.Websphere MQ에서 파일 (문자열이 아님)을 읽고 로컬 드라이브에 저장하십시오.

나는 아래의 코드를 수행 했으므로 문자열 (확실하지 않음)을 Myfile.eff라는 파일에 쓸 수 있습니다. 그러나 이것을 추출 할 때 "Can not Open File"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; 
     } 

내 디렉토리에 정확한 파일을 읽고 쓸 수 있습니까?

미리 감사드립니다.

답변

0

. 해결책은 아래와 같습니다.

MQGetMessageOptions mqGetMsgOpts = new 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 
      } 

감사합니다.

관련 문제