<button label="上传 Image" upload="true,maxsize=1073741824"> <attribute name="onUpload"><![CDATA[ org.zkoss.util.media.Media media = event.getMedia(); String fileName = ""; if(media!=null) fileName = media.getName(); 注:txt(中文内容乱码)java.io.InputStream ins = new java.io.ByteArrayInputStream(media.getStringData().getBytes()); 注:图片java.io.InputStream ins = new java.io.ByteArrayInputStream(media.getByteData()); 注:视频、图片java.io.InputStream ins = new java.io.BufferedInputStream(media.getStreamData()); java.io.File f = new java.io.File("D:\\temp\\"+fileName); if(!f.exists()){ f.createNewFile(); } java.io.OutputStream out = new java.io.FileOutputStream(f); byte[] buf=new byte[1024]; int len; while((len=ins.read(buf))>0){ out.write(buf,0,len); } out.close(); ins.close(); alert("上传成功"); ]]></attribute> </button>
原文:http://www.cnblogs.com/langdangyunliu/p/4106908.html