zk FileUpload(文件上传)

<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>

 上传按扭监听器写法:

uploadBtn.addEventListener(Events.ON_UPLOAD, new EventListener() {

@Override
public void onEvent(Event event) throws Exception {
// TODO Auto-generated method stub

UploadEvent uploadEvent = (UploadEvent) event;
Media media = uploadEvent.getMedia();
}
});

 

解决ZK文件上传中文问题

 

你可能感兴趣的:(fileupload)