-
public interface FileItem
-
Extends java. Io. serializable
This class represents a file or form item that was passed ed withinmultipart/form-dataPOST request.
After retrieving an instance of this class from
FileUploadInstance (see
#parseRequest(javax.servlet.http.HttpServletRequest)), You may either request all contents of the file at once usingget()
Or requestInputStreamWith
getInputStream()And process the file without attempting to load it into memory, which may come handy with large files.
While this interface does not extendjavax.activation.DataSourcePer Se (to avoid a seldom used dependency), several of the defined methods are specifically defined with the same signatures as methods in that interface. This allows an implementation
Of this interface to also implementjavax.activation.DataSourceWith minimal additional work.
Translation:
This class represents an entry in a file or table in a multipart or table-format POST request.
After you passFileUploadAfter obtaining the instance of this class, you can use the get () method to immediately obtain all the content of this file, orgetInputStream()ObtainInputstream, so that you can process this file without loading the file into the memory (especially for large files ).
This interface is not inherited.Javax. Activation. datasource (This avoids unnecessary dependencies), but this interface has several method names andSame in javax. Activation. datasource. In this way, the Implementation class of this interface can be implemented at the minimum cost.javax.activation.DataSource.
Write
void write(File file) throws Exception
-
A convenience method to write an uploaded item to disk. the client code is not concerned with whether or not the item is stored in memory, or on disk in a temporary location. they just want to write the uploaded item to a file.
This method is not guaranteed to succeed if called more than once for the same item. this allows a particle implementation to use, for example, file renaming, where possible, rather than copying all of the underlying data, thus gaining a significant performance
Benefit.
-
Translation:
-
This method is often used to save uploaded items to the hard disk. The client code does not care whether the uploaded content is stored in the memory or in the temporary file directory on the hard disk. The client code only hopes to save the uploaded content as a file to the hard disk.
-
If you call this method repeatedly for the same thing, this method may not be executed repeatedly. However, you can use another method to repeatedly call the write () method. For example, you can rename the file name rather than copying the file content. This can significantly improve the execution efficiency.
-
-
-
Parameters:
-
file-
FileInto which the uploaded item shoshould be stored.
-
Translation:
-
Target file (which file will be saved to the hard disk as the uploaded file)
-
Throws:
-
Exception-If an error occurs.