Java 使用Zk框架上传文件

Java 使用Zk框架上传文件,java,gridview,file-upload,upload,zk,Java,Gridview,File Upload,Upload,Zk,我需要在ZK上传csv文件 这是我的zul页面: <zk> <window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('UploadVM')" title="win" position="center" mode="overlapped" border="normal" width="300px" height="200px">

我需要在ZK上传csv文件 这是我的zul页面:

<zk>
<window
    apply="org.zkoss.bind.BindComposer"
    viewModel="@id('vm') @init('UploadVM')"
    title="win"
    position="center"
    mode="overlapped"
    border="normal"
    width="300px"
    height="200px">
    <button
        label="upload"
        upload="true,maxsize=801192"
        onUpload="@command('uploadFile',upload=event)"
        autodisable="self" />

</window>
</zk>
但在这个简单的例子中,我有以下错误:

Use getStringData() instead
我不知道会发生什么


谁能帮我?

在从媒体获取数据之前,你应该知道媒体的格式。 根据媒体的要求,数据可以是
二进制
基于文本的
格式。要检索其内容,应在前一种情况下使用
getByteData()
getStreamData()
,在后一种情况下使用
getStringData()
getReaderData()
。比如说,

media = event.getMedia();
if (media.isBinary()) {
    InputStream is = media.getStreamData();
} else {
    String s = media.getStringData();
}

在从介质中获取数据之前,您应该知道介质的格式。 根据媒体的要求,数据可以是
二进制
基于文本的
格式。要检索其内容,应在前一种情况下使用
getByteData()
getStreamData()
,在后一种情况下使用
getStringData()
getReaderData()
。比如说,

media = event.getMedia();
if (media.isBinary()) {
    InputStream is = media.getStreamData();
} else {
    String s = media.getStringData();
}

我有一个上传
csv
文件的最好的例子,我想是这样的 将帮助您更好地理解

索引zul

<?page title="Auto Generated index.zul"?>
<window title="Drop here" border="normal" width="100%" height="100%"
    apply="org.zkoss.bind.BindComposer"
    viewModel="@id('vm') @init('com.demo.DropFileViewModel')">

    <dropupload maxsize="5120" detection="none"
        onUpload="@command('doUpload')">
    </dropupload>

    <button label="Download" onClick="@command('doDownload')"></button>


</window> 


谢谢我有一个上传
csv
文件的最好例子
dropupload
,我很喜欢它 将帮助您更好地理解

索引zul

<?page title="Auto Generated index.zul"?>
<window title="Drop here" border="normal" width="100%" height="100%"
    apply="org.zkoss.bind.BindComposer"
    viewModel="@id('vm') @init('com.demo.DropFileViewModel')">

    <dropupload maxsize="5120" detection="none"
        onUpload="@command('doUpload')">
    </dropupload>

    <button label="Download" onClick="@command('doDownload')"></button>


</window> 


谢谢

这是我生成PDF文档的解决方案:

@Command
@NotifyChange("savePDF")
public void savePDF() throws IOException, Exception {

File f = new File("PDF_test.pdf");
OutputStream file = new FileOutputStream(f); 

Document document = new Document();
PdfWriter.getInstance(document, file);

Filedownload.save(f, "application/pdf");

PdfPTable table=new PdfPTable(3);
PdfPCell cell .....
}

这是我生成PDF文档的解决方案:

@Command
@NotifyChange("savePDF")
public void savePDF() throws IOException, Exception {

File f = new File("PDF_test.pdf");
OutputStream file = new FileOutputStream(f); 

Document document = new Document();
PdfWriter.getInstance(document, file);

Filedownload.save(f, "application/pdf");

PdfPTable table=new PdfPTable(3);
PdfPCell cell .....
}

如果我有一个csv文件,每行读取一行,我会做什么?因为我是否需要getstream数据?@user2768380使用
media.getReaderData()
并用
BufferedReader
包装生成的读卡器,如果我有一个csv文件,每行读取一行,我会做什么?,因为我是否需要getstream数据?@user2768380使用
media.getReaderData()
并用
BufferedReader