【发布时间】:2017-05-30 06:40:21
【问题描述】:
我是 Java 新手。我想向列表中添加一个元素。
List<RequestAttachmentDTO> attachments
RequestAttachmentDTO 类在这里,
public class RequestAttachmentDTO {
byte[] contentStream;
String fileName;
String contentType;
String contentTransferEncoding;
public RequestAttachmentDTO(byte[] contentStream, String fileName, String contentType) {
this.contentStream = contentStream;
this.fileName = fileName;
this.contentType = contentType;
}
public RequestAttachmentDTO(byte[] contentStream, String fileName, String contentType,String contentTransferEncoding) {
this.contentStream = contentStream;
this.fileName = fileName;
this.contentType = contentType;
this.contentTransferEncoding=contentTransferEncoding;
}
public String getFileName() {
return fileName;
}
public String getContentType() {
return contentType;
}
public byte[] getContentStream() {
return contentStream;
}
public String getContentTransferEncoding() {
return contentTransferEncoding;
}
}
这就是我尝试添加的方式,
String fieldName = item.getFieldName();
String fiileName = FilenameUtils.getName(item.getName());
fileContent = item.getInputStream();
Path path = Paths.get("/data/uploads/form_urlencoded_simple_decoded_body.txt");
byte[] data = Files.readAllBytes(path);
List<RequestAttachmentDTO> attachments = new ArrayList<>();
attachments.add(data,fieldName,"application/x-www-form-urlencoded");
它不接受它。
PS:- 文件item 是从multipart/form-data 编码的JSP 页面上传的。
你能帮我在这个列表中添加元素吗?谢谢。
【问题讨论】:
-
"String fileName =" ...你的代码有错别字吗?
标签: java jersey multipartform-data apache-commons