FileUpload,如何将文件保存在数组中:UploadedFile [] PictabTest = new UploadedFile [10];

时间:2018-11-19 14:36:16

标签: java jsf primefaces

Primefaces JSF应用程序确实上传了一个文件,以存储在UploadedFile []表中。 (该表稍后用于存储多个文件)将文件加载到数组中后,我正在通过读取大小来测试内容。 读取名称可以正常工作,但不能读取大小。

我的简化问题是:当我从另一种方法读取表时,如何声明表UploadedFile []以避免文件消失? 我更喜欢ArrayList,但可能很难,因为ArrayList仅保存引用..?

    The output is following:

Filename from the event works OK : bilde_5.jpg
Filesize from the event works Ok: 62528
Filename from the array works Ok : bilde_5.jpg
Filesize from the array works Ok: 62528
Reading the Filename in the array from ANOTHER method  Works OK: bilde_5.jpg
WORKS NOT OK: Reading the Filesize in the same array from ANOTHER method: 0
private  UploadedFile[] PictabTest = new UploadedFile[10];

    public void handleFileUpload(FileUploadEvent event)
    {
        PictabTest[0] = event.getFile();
             System.out.println("Filename from the event works OK : " + event.getFile().getFileName() );   
             System.out.println("Filesize from the event works Ok: " +  event.getFile().getSize() ); 

             System.out.println("Filename from the array works Ok : " + PictabTest[0].getFileName() ); 
             System.out.println("Filesize from the event works Ok: " + PictabTest[0].getSize()  );           
    }


    public void testTable()
    {

        System.out.println("Reading the Filename in the array from another method  Works OK: " + PictabTest[0].getFileName() );   // Works OK
        System.out.println("WORKS NOT OK: Reading the Filesize in the same array from ANOTHER method: " + PictabTest[0].getSize()  ); // WORKS NOT, returns ZERO WHY????????
    }

0 个答案:

没有答案