---
title: "用commons-uploadfile上传文件"
author: "skymr"
date: "2010-04-13T17:52:12Z"
tags: ["Apache", "HTML"]
categories: ["编程语言"]
slug: "commons-uploadfile"
draft: false
lastmod: "2010-04-13T17:52:12Z"
id: 643041
url: "https://skymr.iteye.com/blog/643041"
---

```
	<form enctype="multipart/form-data" action="upload" name="uploadForm" method="post">
		文件：<input type="file" name="fileOne" size="40"/>
		<textarea name="fileOneDesc" cols="50" rows="4" id="fileOneDesc"></textarea><br>
		文件：<input type="file" name="fileTwo" size="40"/>
		<textarea name="fileTwoDesc" cols="50" rows="4" id="fileTwoDesc"></textarea><br>
		文件：<input type="file" name="fileThree" size="40"/>
		<textarea name="fileThreeDesc" cols="50" rows="4" id="fileThreeDesc"></textarea><br>
		<input type="submit" value="开始上传">
	</form>
```

```
		DiskFileUpload fu = new DiskFileUpload();
		fu.setRepositoryPath("E:/");//设置上传路径
		try {
			List fileItems = fu.parseRequest(req);
			FileItem fi = (FileItem)fileItems.get(0);//这里只是取得第一个文件
			System.out.println(fi.getName());
			fi.write(new File("E:/a.txt"));//保存
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
```

 需要2个jar

common-upload和common-io,可到[http://commons.apache.org/](http://commons.apache.org/)去下载,还有帮助文档[http://commons.apache.org/fileupload/apidocs/index.html](http://commons.apache.org/fileupload/apidocs/index.html)

这里会附上common-upload

 还有源代码

commons-io