我正在使用 Apache Commons FileUpload 库来上传文件。我想将 InputStream 的内容复制到一个单字节数组中。我怎么能那样做?
try {
List<FileItem> items = new ServletFileUpload(
new DiskFileItemFactory()).parseRequest(request);
for (FileItem item : items) {
if (item.isFormField()) {
// Process regular form field (input
// type="text|radio|checkbox|etc", select, etc).
String fieldname = item.getFieldName();
String fieldvalue = item.getString();
out.println("returned");
} else {
// Process form file field (input type="file").
String fieldname = item.getFieldName();
String filename = FilenameUtils.getName(item.getName());
InputStream input = item.getInputStream();
if (fieldname.equals("file")) {
// please help me here.
byte[] allbyte = ???
}
}
}
}