Please refer the below code.

Here we will receive message simple file creation then writing bytes coming from BytesMessageObject until EOF occurs.

BytesMessage bm = (BytesMessage)topicSubscriber.receiveNoWait(); // receive(1000);

System.out.println("bm-->"+bm);

if(bm !=null){

File file = new File("D:/jms/myfie.txt"); //file created

FileOutputStream fos = new FileOutputStream(file);//create fileoutput stream

BufferedOutputStream outBuf = new BufferedOutputStream(fos);//create bufferoutputstream

int i;

while((i=bm.readInt())!=-1)//read unitil EOF means -1

{

outBuf.write(i);//write it to the file

}

System.out.println("outBuf-->"+outBuf);

System.out.println(file.isFile());

outBuf.close();//close output buffer

fos.close();//close file ouput stream

}

Here the file is opened then

Wrote in BytesMessageObject.

Sent Across the Queue

Sender code :

File f=new File("D:/Import.txt");//get file handle

System.out.println("is File "+f.isFile());

BytesMessage bm = topicSession.createBytesMessage();//create bytes message

InputStream in= new FileInputStream(f);//create input stream with file handle

BufferedInputStream inBuf= new BufferedInputStream(in);//create buffer input stream

int i;

while((i=inBuf.read())!=-1)//read file until EOF(-1) is reached{

bm.writeInt(i);//write in bytesmessage

}

System.out.println("after while");

//adding an eof

bm.writeInt(-1);//add EOF in bytes message

System.out.println("BM = "+bm);

topicPublisher.send(bm);///send the bytes message

System.out.println("sent successfully");

topicConnection.stop();//stop connection

2015-07-23 12:42:19

+0

请不要随便倾倒一些代码。解释你的代码如何实际解决问题中的问题。 –

2015-07-23 13:03:39

+0

@ekad现在回答说明 –

2015-07-24 06:27:58

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐