1 Reply Latest reply on Apr 24, 2008 1:41 PM by nohacks

    fileUpload --- Saving files to disk ??

      Hey Guys,

      I would like to use rich:fileUpload.

      I have the listener listed below. Could someone tell me where to write the file to disk?

      I have the code below I was using with myfaces writing out the file to disk. How can I call this code with rich:fileUpload??

      Thanks
      Phil

      public void listener(UploadEvent event) throws IOException{
      UploadItem item = event.getUploadItem();
      File file = new File();
      file.setLength(item.getData().length);
      file.setName(item.getFileName());
      file.setData(item.getData());
      files.add(file);
      uploadsAvailable--;


      }

      public String writeFileToDisk()
      {
      try {
      InputStream stream = theFile.getInputStream();
      long fSize = theFile.getSize();
      byte [] buffer = new byte[(int)fSize];
      stream.read(buffer, 0, (int)fSize);
      stream.close();
      FileOutputStream fos = new FileOutputStream(new File("c:\\newfile.out"));
      fos.write(buffer);
      fos.close();
      } catch (Exception ioe) {
      ioe.printStackTrace();
      }
      return "success";
      }