How can a user download a file in client side (Google Web Toolkit)

前端 未结 4 1885
执笔经年
执笔经年 2020-11-30 12:58

I\'m using GWT(Google Web Toolkit) to make a website. I need to show a table to the user, and let the user download the contents of the table.

On the client side, h

4条回答
  •  星月不相逢
    2020-11-30 13:23

    To complete the answer of number one item in the io part...

    you can refer to this link

    http://www.programcreek.com/2009/02/java-convert-a-file-to-byte-array-then-convert-byte-array-to-a-file/

    or refer to this code

    File file = new File(enter the filepath here)
    FileInputStream fis = new FileInputStream(file);
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    byte[] buf = new byte[1024];
                    try {
                        for (int readNum; (readNum = fis.read(buf)) != -1;) {
                            bos.write(buf, 0, readNum); //no doubt here is 0
                            //Writes len bytes from the specified byte array starting at offset off to this byte array output stream.
                            System.out.println("read " + readNum + " bytes,");
                        }
                    } catch (IOException ex) {
                        System.err.println("unable to convert to bytes");
                    }
                    byte[] bytes = bos.toByteArray();
                    outputStream.write(bytes);
                    outputStream.flush();
                    outputStream.close();
    

    hope it helps!

提交回复
热议问题