org.apache.commons.fileupload. FileItem-api

来源:互联网 发布:苏州管家婆软件 编辑:程序博客网 时间:2024/06/06 00:41
 
public interface FileItem
extends java.io.Serializable

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

After retrieving an instance of this class from a FileUpload instance (see #parseRequest(javax.servlet.http.HttpServletRequest)), you may either request all contents of the file at once usingget() or request an InputStream with getInputStream() and process the file without attempting to load it into memory, which may come handy with large files.

While this interface does not extend javax.activation.DataSource per 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 implement javax.activation.DataSource with minimal additional work.

翻译:

这个类代表一个多部分或者表格格式数据的POST请求的一个文件或者表格里面的条目。

在你通过FileUpload 类的实例获取这个类的实例之后,你可以通过get()方法马上获得这个文件的全部内容,或者通过getInputStream()获得一个InputStream,从而使得你可以在不需要将文件加载到内存中的情况底下处理这个文件(在大文件的情况下尤其适合)。

这个接口本身没有继承javax.activation.DataSource(这样子做避免了不必要的依赖),但是这个接口中有几个方法名与javax.activation.DataSource中的一样。这样子做,使得这个接口的实现类可以在最少的代价之下就可以实现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 particular implementation to use, for example, file renaming, where possible, rather than copying all of the underlying data, thus gaining a significant performance benefit.

翻译:

这个方法经常用于将上传的东西保存到硬盘中去。客户端代码不关心这个上传来的东西是保存在内存中还是在硬盘中的临时文件目录下。客服端代码只是希望将这个上传来的东西可以作为一个文件保存到硬盘中去。

如果对于同一个东西,重复调用这个方法,这个方法不一定会重复执行。但是,你可以使用另外的办法来实现重复调用write()方法。比如你可以通过文件名重命名而不是复制文件内容的方式来实现。这样子做可以明显地提高执行效率。

Parameters:
file - The File into which the uploaded item should be stored.
翻译:
目标文件(上传而来的东西将作为哪个文件保存到硬盘中)
Throws:
Exception - if an error occurs.

 

 

原创粉丝点击