2 Replies Latest reply: Jun 26, 2013 4:01 AM by Tarek Fathy RSS

    probkem in copying  a file to another directory

    Tarek Fathy

      hi

      my page contains  af:inputfile.

       <af:inputFile label="#{viewcontrollerBundle.SELECT_FILE}" id="if1" value="#{docbean.file}"/>
      

       

      the user should use this page to browse any file in his machine and uploaded to server

       

      I use  FileUtils.copyFileToDirectory() to copy the file to the directory. this method comes from org.apache.myfaces.trinidad.model.UploadedFile;

       

      This is the method body

       

      import org.apache.myfaces.trinidad.model.UploadedFile;
      ....
          public void uploadToServer(ActionEvent actionEvent) {
              UploadedFile myFile = (UploadedFile)this.getFile();       
                  File outputFile =         
                      new File("D:\\SystemsData\\ScannedFiles\\" + this.getCurrentDocId() + ".tif");
                  try {
                      FileUtils.copyFileToDirectory((File)myFile, outputFile);
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
      

       

      at run time when I press upload button I get this error

      java.lang.ClassCastException: org.apache.myfaces.trinidadinternal.config.upload.UploadedFiles$FixFilename cannot be cast to java.io.File
      

      My Question is:

      how to cast org.apache.myfaces.trinidadinternal.config.upload.UploadedFiles  to java.io.File