fileitem⽅法_JavaFileItem.write⽅法代码⽰例
本⽂整理汇总了Java中org.apachemons.fileupload.FileItem.write⽅法的典型⽤法代码⽰例。如果您正苦于以下问题:Java FileItem.write⽅法的具体⽤法?Java FileItem.write怎么⽤?Java FileItem.write使⽤的例⼦?那么恭喜您, 这⾥精选的⽅法代码⽰例或许可以为您提供帮助。您也可以进⼀步了解该⽅法所在类org.apachemons.fileupload.FileItem的⽤法⽰例。
在下⽂中⼀共展⽰了FileItem.write⽅法的16个代码⽰例,这些例⼦默认根据受欢迎程度排序。您可以为喜欢或者感觉有⽤的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码⽰例。
⽰例1: handle
点赞 3
import org.apachemons.fileupload.FileItem; //导⼊⽅法依赖的package包/类
@Override
public void handle( List fileItems )
{
for ( FileItem file : fileItems )
{
byte[] fileName = Name().getBytes();
try
{
String uploadName = new String( fileName, "utf-8" );
System.out.println( uploadName );
File writeFile = new File( "D:\\" + uploadName );
file.write( writeFile );
} catch ( Exception e )
{
/
/ TODO Auto-generated catch block
e.printStackTrace();
}
}
}
开发者ID:guanhaobi,项⽬名称:DataStage,代码⾏数:26,
⽰例2: store
点赞 3
import org.apachemons.fileupload.FileItem; //导⼊⽅法依赖的package包/类
public static void store(DocFile doc, FileItem fileItem) {
String fullPath = getFullPath(doc);
File file = new File(fullPath);
if (file.isFile()) {
log.warn("File " + fullPath + " exists: will be overwritten!");
}
File dir = ParentFile();
if (!ists()) {
dir.mkdirs();
log.info("Creating directory " + AbsolutePath());
}
try {
fileItem.write(file);
} catch (Exception ex) {
log.fatal(ex);
}
}
开发者ID:unsftn,项⽬名称:bisis-v4,代码⾏数:18,
⽰例3: doUpload
点赞 2
import org.apachemons.fileupload.FileItem; //导⼊⽅法依赖的package包/类
@Override
protected void doUpload(HttpServletRequest request, Document document, FileItem item) throws Exception {
File fullFile = new Name());
String Name().replaceFirst(".*\\.", ".");
if(CertificateManager.isCertificateExtension(certifNameExtension)){
File savedFile = new File(getRepository(), Name());
item.write(savedFile);
ServiceUtils.addMessage(document, DocumentElement(), "The certificate \""+Name()+"\" has been successfully uploaded", "message", false);
}
else{
ServiceUtils.addMessage(document, DocumentElement(), "The extension \""+certifNameExtension+"\" isn't valid", "error", false);
}
}
开发者ID:convertigo,项⽬名称:convertigo-engine,代码⾏数:14,
⽰例4: saveFileItem
点赞 2
import org.apachemons.fileupload.FileItem; //导⼊⽅法依赖的package包/类
private void saveFileItem(FileItem item) throws Exception {
String[] fileNameParts = new Name()).getName().split("\\" +
".");
String suffix = "." + fileNameParts[1];
String prefix = fileNameParts[0];
File storeFile = ateTempFile(prefix, suffix);
item.write(storeFile);
log.info("UPLOADED FILE IS - " + AbsolutePath());
}
开发者ID:tapack,项⽬名称:satisfy,代码⾏数:10,
⽰例5: receiveFile
点赞 2
import org.apachemons.fileupload.FileItem; //导⼊⽅法依赖的package包/类
@SuppressWarnings({ "unchecked" })
private void receiveFile(HttpServletRequest request, OnFileReceiveListener listener) throws Exception{ DiskFileItemFactory factory = new DiskFileItemFactory();
// 临时⽂件夹路径
String repositoryPath = Manager().FILE_TEMP_PATH;
// 设定临时⽂件夹为repositoryPath
File fileTempFolder = new File(repositoryPath);
if(!ists())fileTempFolder.mkdirs();
factory.setRepository(fileTempFolder);
// 设定上传⽂件的阈值,如果上传⽂件⼤于1M,就可能在repository
// 所代 表的⽂件夹中产⽣临时⽂件,否则直接在内存中进⾏处理
factory.setSizeThreshold(1024 * 1024);
// 创建⼀个ServletFileUpload对象
ServletFileUpload uploader = new ServletFileUpload(factory);
// 调⽤uploader中的parseRequest⽅法,可以获得请求中的相关内容,
// 即⼀个FileItem类型的ArrayList。FileItem是在
// org.apachemons.fileupload中定义的,它可以代表⼀个⽂件,
getsavefilename/
/ 也可以代表⼀个普通的form field
ArrayList list = (ArrayList) uploader.parseRequest(request);
for (FileItem fileItem : list){
if (!fileItem.isFormField()){ // 如果是⽂件
String fileName = Name() + UUID.randomUUID();
// 将其中包含的内容写到指定⽬录下名为fileName的⽂件中
File file = new Manager().FILE_SAVE_PATH + File.separator + fileName); ateNewFile();
//System.out.Path());
fileItem.write(file);
break;//⼀次请求只接受⼀个⽂件
}
}
}
开发者ID:landriesnidis,项⽬名称:PCloud_Server_v3,代码⾏数:39,
⽰例6: uploadFiles
点赞 2
import org.apachemons.fileupload.FileItem; //导⼊⽅法依赖的package包/类
/**
* @param request
* @return
* @throws IOException
*/
public static Map uploadFiles(HttpServlet servlet, HttpServletRequest request) {
Map map = wHashMap();
Map fileMap = wHashMap();
map.put("file", fileMap);
DiskFileItemFactory factory = new DiskFileItemFactory();// 创建⼯⼚
factory.setSizeThreshold(1024 * 1024 * 30);// 设置最⼤缓冲区为30M
// 设置缓冲区⽬录
String savePath = ServletContext().getRealPath("/WEB-INF/temp");
factory.setRepository(new File(savePath));
FileUpload upload = new FileUpload(factory);// 获得上传解析器
upload.setHeaderEncoding("UTF-8");// 解决上传⽂件名乱码
try {
String targetFolderPath = ServletContext().getRealPath("/WEB-INF/" + Property("web.files.upload.folder"));
File targetFolder = new File(targetFolderPath);// ⽬标⽂件夹
if(!ists()) {
targetFolder.mkdir();
}
List fileItems = upload.parseRequest(new ServletRequestContext(request));// 解析请求体
for (FileItem fileItem : fileItems) {
if (fileItem.isFormField()) {// 判断是普通表单项还是⽂件上传项
String name = FieldName();// 表单名
String value = String("UTF-8");// 表单值
map.put(name, value);
} else {// ⽂件上传项
String fileName = Name();// 获取⽂件名
if (StringUtils.isEmpty(fileName))// 判断是否上传了⽂件
continue;
// 截取⽂件名
int index = fileName.lastIndexOf("/");
if (index > -1) {
fileName = fileName.substring(index);
}
/
/ 检查⽂件是否允许上传
index = fileName.lastIndexOf(".");
if (index > -1 && index < fileName.length() - 1) {
String ext = fileName.substring(index + 1).toLowerCase();
if (!String("web.sion").contains(";" + ext + ";")) {
LOGGER.warn("The file {} is not allowed to upload.", fileName);
continue;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论