The realization idea is:
1. User login to the receiving party
2. Get the file sender user name
3. Get the file name you want to receive
4. Get the file size you want to receive
5. Set the file storage path
6. Receiving files
The implementation code is:
public int Settransfilecallback (final Method method,final Object instance, final String Downloadedir) { Filetransfermanager Transfermanager = new Filetransfermanager (this.connection); Transfermanager.addfiletransferlistener (New Filetransferlistener () {public void Filetransferrequest (final Filetransferrequest request) {String Fromwhere = Request.getrequestor (); int pos = Fromwhere.lastindexof (' @ '); String from = fromwhere.substring (0, POS), if (!from.equals ("Sharefilemanager")) Swingutilities.invokelater (new Runnable () {public void run () {String fileName = Request.getfilename (); Long fileSize = Request.getfilesize (); String requestor = Request.getrequestor (); String Barejid = org.jivesoftware.smack.util.StringUtils.parseBareAddress (requestor); Byteformat format = new Byteformat (); String Text = Format.format (fileSize); Incomingfiletransfer transfer = Request.accept (); File Filecreate = new file (Downloadedir), if (!filecreate.exists ()) {filecreate.mkdirs ();} File Downloadedfile = new file (Downloadedir,Request.getfilename ()); try {transfer.recievefile (downloadedfile); while (true) {if (transfer.getstatus () = = FileTransfer.Status.complete) {try {Method.invoke (instance,new object[] {filename,barejid, text,downloadedir});} catch (IllegalArgumentException e) {e.printstacktrace ();} catch (Illegalaccessexception e) {e.printstacktrace ();} catch (InvocationTargetException e) {e.printstacktrace ();} return;} try {thread.sleep (10L);} catch (Interruptedexception e) {e.printstacktrace ();}}} catch (Xmppexception e) {e.printstacktrace ();}}});}); return 0;}
Realization of file receiving function of instant chat system based on smack