Search code examples
javaapache-commons

Convertion from File Object to FileItem Object


I would like to transform this entire File (java.io.File) to FileItem (org.apache.commons.fileupload.FileItem)

Can any one provide the code snip for this.

Help me on this.


Solution

  • From FileItem's javadoc:

    This class represents a file or form item that was received within a multipart/form-data POST request

    From File's javadoc:

    An abstract representation of file and directory pathnames.

    They both denote completely different concepts. There's no guarantee that a FileItem has an equivalent on disk (which could be pointed to as a java.io.File)

    This makes me think that this is a x-y-problem and you should rephrase your question with the underlying problem.