fileitem方法_JavaFileItem.write方法代码示例

fileitem方法_JavaFileItem.write方法代码示例

2023年7月3日发(作者:)

fileitem⽅法_⽅法代码⽰例本⽂整理汇总了Java中⽅法的典型⽤法代码⽰例。如果您正苦于以下问题:⽅法的具体⽤法?Java 怎么⽤?Java 使⽤的例⼦?那么恭喜您, 这⾥精选的⽅法代码⽰例或许可以为您提供帮助。您也可以进⼀步了解该⽅法所在类em的⽤法⽰例。在下⽂中⼀共展⽰了⽅法的16个代码⽰例,这些例⼦默认根据受欢迎程度排序。您可以为喜欢或者感觉有⽤的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码⽰例。⽰例1: handle点赞 3import em; //导⼊⽅法依赖的package包/类@Overridepublic void handle( List fileItems ){for ( FileItem file : fileItems ){byte[] fileName = e().getBytes();try{String uploadName = new String( fileName, "utf-8" );n( uploadName );File writeFile = new File( "D:" + uploadName );( writeFile );} catch ( Exception e ){// TODO Auto-generated catch tackTrace();}}}开发者ID:guanhaobi,项⽬名称:DataStage,代码⾏数:26,⽰例2: store点赞 3import em; //导⼊⽅法依赖的package包/类public static void store(DocFile doc, FileItem fileItem) {String fullPath = getFullPath(doc);File file = new File(fullPath);if (()) {("File " + fullPath + " exists: will be overwritten!");}File dir = entFile();if (!()) {();("Creating directory " + olutePath());}try {(file);} catch (Exception ex) {(ex);}}开发者ID:unsftn,项⽬名称:bisis-v4,代码⾏数:18,⽰例3: doUpload点赞 2import em; //导⼊⽅法依赖的package包/类@Overrideprotected void doUpload(HttpServletRequest request, Document document, FileItem item) throws Exception {File fullFile = new File(e());String certifNameExtension=e().replaceFirst(".*.", ".");if(ificateExtension(certifNameExtension)){File savedFile = new File(getRepository(), e());(savedFile);sage(document, umentElement(), "The certificate ""+e()+"" has beensuccessfully uploaded", "message", false);}else{sage(document, umentElement(), "The extension ""+certifNameExtension+"" isn'tvalid", "error", false);}}开发者ID:convertigo,项⽬名称:convertigo-engine,代码⾏数:14,⽰例4: saveFileItem点赞 2import em; //导⼊⽅法依赖的package包/类private void saveFileItem(FileItem item) throws Exception {String[] fileNameParts = new File(e()).getName().split("" +".");String suffix = "." + fileNameParts[1];String prefix = fileNameParts[0];File storeFile = TempFile(prefix, suffix);(storeFile);("UPLOADED FILE IS - " + olutePath());}开发者ID:tapack,项⽬名称:satisfy,代码⾏数:10,⽰例5: receiveFile点赞 2import em; //导⼊⽅法依赖的package包/类@SuppressWarnings({ "unchecked" })private void receiveFile(HttpServletRequest request, OnFileReceiveListener listener) throws Exception{DiskFileItemFactory factory = new DiskFileItemFactory();// 临时⽂件夹路径String repositoryPath = ager().FILE_TEMP_PATH;// 设定临时⽂件夹为repositoryPathFile fileTempFolder = new File(repositoryPath);if(!())();ository(fileTempFolder);// 设定上传⽂件的阈值,如果上传⽂件⼤于1M,就可能在repository// 所代 表的⽂件夹中产⽣临时⽂件,否则直接在内存中进⾏处理eThreshold(1024 * 1024);// 创建⼀个ServletFileUpload对象ServletFileUpload uploader = new ServletFileUpload(factory);// 调⽤uploader中的parseRequest⽅法,可以获得请求中的相关内容,// 即⼀个FileItem类型的ArrayList。FileItem是在// load中定义的,它可以代表⼀个⽂件,// 也可以代表⼀个普通的form fieldArrayList list = (ArrayList) equest(request);for (FileItem fileItem : list){if (!Field()){ // 如果是⽂件String fileName = e() + UUID();// 将其中包含的内容写到指定⽬录下名为fileName的⽂件中File file = new File(ager().FILE_SAVE_PATH + tor + fileName);NewFile();//n(h());(file);shed(5CodeByFile(file),fileName,());break;//⼀次请求只接受⼀个⽂件}}}开发者ID:landriesnidis,项⽬名称:PCloud_Server_v3,代码⾏数:39,⽰例6: uploadFiles点赞 2import em; //导⼊⽅法依赖的package包/类/*** @param request* @return* @throws IOException*/public static Map uploadFiles(HttpServlet servlet, HttpServletRequest request) {Map map = hMap();Map fileMap = hMap();("file", fileMap);DiskFileItemFactory factory = new DiskFileItemFactory();// 创建⼯⼚eThreshold(1024 * 1024 * 30);// 设置最⼤缓冲区为30M// 设置缓冲区⽬录String savePath = vletContext().getRealPath("/WEB-INF/temp");ository(new File(savePath));FileUpload upload = new FileUpload(factory);// 获得上传解析器derEncoding("UTF-8");// 解决上传⽂件名乱码try {String targetFolderPath = vletContext().getRealPath("/WEB-INF/" +perty(""));File targetFolder = new File(targetFolderPath);// ⽬标⽂件夹if(!()) {();}List fileItems = equest(new ServletRequestContext(request));// 解析请求体for (FileItem fileItem : fileItems) {if (Field()) {// 判断是普通表单项还是⽂件上传项String name = ldName();// 表单名String value = ing("UTF-8");// 表单值(name, value);} else {// ⽂件上传项String fileName = e();// 获取⽂件名if (y(fileName))// 判断是否上传了⽂件continue;// 截取⽂件名int index = dexOf("/");if (index > -1) {fileName = ing(index);}// 检查⽂件是否允许上传index = dexOf(".");if (index > -1 && index < () - 1) {String ext = ing(index + 1).toLowerCase();if (!ing("ion").contains(";" + ext + ";")) {("The file {} is not allowed to upload.", fileName);continue;}}// ⽣成唯⼀⽂件名,保留原⽂件名String newFileName = UUID().toString();// 将⽂件内容写到服务器端String targetPath = targetFolderPath + "/" + newFileName;File targetFile = new File(targetPath);// ⽬标⽂件NewFile();(targetFile);();// 删除临时⽂件(fileName, newFileName);}}} catch (Exception e) {tackTrace();}return map;}开发者ID:menyouping,项⽬名称:jw,代码⾏数:74,⽰例7: processFileUpload点赞 2import em; //导⼊⽅法依赖的package包/类/*** Parse file and save.** @param request request.* @param saveDirectory save directory.* @throws Exception may be.*/private void processFileUpload(HttpRequest request, File saveDirectory) throws Exception {FileItemFactory factory = new DiskFileItemFactory(1024 * 1024, saveDirectory);HttpFileUpload fileUpload = new HttpFileUpload(factory);// Set upload process listener.// gressListener(new ProgressListener(){...});List fileItems = equest(new HttpUploadContext((HttpEntityEnclosingRequest) request));for (FileItem fileItem : fileItems) {if (!Field()) { // File param.// Attribute.// tentType();// ldName();// e();// e();// ing();File uploadedFile = new File(saveDirectory, e());// 把流写到⽂件上。(uploadedFile);} else { // General key = e();String value = ing();}}}开发者ID:yanzhenjie,项⽬名称:AndServer,代码⾏数:35,⽰例8: executePost点赞 2import em; //导⼊⽅法依赖的package包/类public void executePost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{String path = getPath(request);String thePath = fileBasePath+"uploads/"; //TODO calculate the directory path for this file///TODO: thePath will be dependent on a verb retrieved from request/String verb = getVerb(path);String userId = "";if (("uUpload") ||("muUpload")) {n("UserUpload "+thePath);//user uploaduserId = getUserId(path);String tempPath = thePath+userId;File dir = new File(tempPath);if (!()) {boolean foo = ();n("MADEDIR "+foo);}thePath = olutePath();}try {n("UPLOADING TO "+verb+" | "+userId+" | "+thePath);File repository = new File(thePath);String uploadPath = olutePath()+"/";DiskFileItemFactory dfiFactory = dfiFactory = new DiskFileItemFactory();ository(repository);ServletFileUpload servletFileUpload = new ServletFileUpload(dfiFactory);n("PARSING");List items = equest(request);n("FILEUPLOADING "+path+" | "+());Iterator iter = or();while (t()) {FileItem item = ();String fileName = e();if (Field()) {//TODO processFormField(item);} else {//TODOprocessUploadedFile(item);File f = new File(uploadPath+fileName);(f);}//TODO would be nice to have a socket and show progress} } catch (Exception e) {or(sage(), e);tackTrace();}if (("uUpload"))direct("/gui");elsesendHTML("ok", response);}开发者ID:topicquests,项⽬名称:backside-servlet-ks,代码⾏数:55,⽰例9: upload点赞 2import em; //导⼊⽅法依赖的package包/类/*** Upload a file into the given directory.** @param request* - the HttpServletRequest object* @param response* - the HttpServletResponse object* @param dir* - the directory in which the files/directories are deleted* @param fileItemList* - the list with the uploaded files*/private void upload(HttpServletRequest request, File dir,List fileItemList) {if (fileItemList == null) {return;}// Process the uploaded itemsIterator it = or();while (t()) {FileItem item = ();// Process a file uploadif (!Field()) {String name = e();int i = dexOf("/");if (i < 0) {i = dexOf("");}if (i >= 0) {name = ing(i + 1);}File file = new File(dir, name);if (isAccessible(request, file)) {try {(file);BssClient bssClient = new BssClient(oteHost());Event(getSaasId(request),_ID_FILE_UPLOAD,getUserId(request), MULTIPLIER);} catch (Exception e) {tackTrace();}}}}}开发者ID:servicecatalog,项⽬名称:oscm,代码⾏数:54,⽰例10: processRequest点赞 2import em; //导⼊⽅法依赖的package包/类public Object processRequest(HttpServletRequest request) throws Exception {HttpServletRequestTwsWrapper twsRequest = request instanceof HttpServletRequestTwsWrapper ?(HttpServletRequestTwsWrapper) request : null;File temporaryFile = null;try {// Check multipart requestif (ipartContent(request)) {("(ntext) Multipart resquest");// Create a factory for disk-based file itemsDiskFileItemFactory factory = new DiskFileItemFactory();// Set factory eThreshold(1000);temporaryFile = TempFile("c8o-multipart-files", ".tmp");int cptFile = 0;();();ository(temporaryFile);("(ntext) Temporary folder for upload is : " +olutePath());// Create a new file upload handlerServletFileUpload upload = new ServletFileUpload(factory);// Set overall request size eMax(pertyAsLong(_UPLOAD_MAX_REQUEST_SIZE));eSizeMax(pertyAsLong(_UPLOAD_MAX_FILE_SIZE));// Parse the requestList items = (equest(request));for (FileItem fileItem : items) {String parameterName = ldName();String parameterValue;if (Field()) {parameterValue = ing();("(ntext) Value for field '" + parameterName + "' : " + parameterValue);} else {String name = e().replaceFirst("^.*(?:|/)(.*?)$", "$1");if (() > 0) {File wDir = new File(temporaryFile, "" + (++cptFile));();File wFile = new File(wDir, name);(wFile);();parameterValue = olutePath();("(ntext) Temporary uploaded file for field '" + parameterName + "' : " +parameterValue);} else {("(ntext) No temporary uploaded file for field '" + parameterName + "',empty name");parameterValue = "";}}if (twsRequest != null) {ameter(parameterName, parameterValue);}}}Requester requester = getRequester();ribute("ter", requester);Object result = sRequest(request);processRequestEnd(request, requester);return result;} finally {if (temporaryFile != null) {try {("(GenericServlet) Removing the temporary file : " + olutePath());Directory(temporaryFile);} catch (IOException e) { }}}}开发者ID:convertigo,项⽬名称:convertigo-engine,代码⾏数:78,⽰例11: doUpload点赞 2import em; //导⼊⽅法依赖的package包/类protected void doUpload(HttpServletRequest request, Document document, FileItem item) throws Exception {File fullFile = new File(e());File savedFile = new File(getRepository(), e());(savedFile);}开发者ID:convertigo,项⽬名称:convertigo-engine,代码⾏数:6,⽰例12: doPost点赞 2import em; //导⼊⽅法依赖的package包/类/*** Metóda doPost je obslužná metóda, ktorá sa volá po vyvolaní daného servletu na strane používateľa.* Pričom sa servlet vykonáva na strane servera.* @param request - objekt požiadavky, ktorý sa prenáša zo strany klienta na stranu servera* @param response - objekt odozvy servera, ktorý sa prenáša zo strany servera na stranu klienta* @throws ServletException* @throws IOException*/@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {List items = null;try {items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);} catch (FileUploadException e) {throw new ServletException("Cannot parse multipart request.", e);}for (FileItem item : items) {if (Field()) {// Process regular form fields here the same way as ameter().// You can get parameter name by ldName();// You can get parameter value by ing();//n(());//trackName = (0).getString();//n((0).getString());} else {//n(e());try {HttpSession session = sion();ribute("isMultimedia", "True");String trackName = ribute("trackName").toString();if(With("Windows")){path = _DATA_STORAGE + ribute("username") + "" + "Temp" + "" + "Multimedia" + "";//path = "E:SCHOOLTUKEDIPLOMOVKAPRAKTICKACASTGITHUBGPSWebAppwebLoggeduploaded_from_server" + ribute("username") + "" +"Temp" + "" + "Multimedia" + "";}else{path = _DATA_STORAGE + ribute("username") + "/" + "Temp" + "/" + "Multimedia" + "/";}new File(path).mkdirs();String tmpFileName = ize(e(), );String fileNameTMP = eAll("[^x00-x7F]", "");String fileName = eAll("[,|;]", "");n("SUBORIK: " + fileName);(new File(path, fileName));tance().createNewLog("Successfuly uploaded multimedia file " + fileName + " in user's " +ribute("username") + " track " + trackName + " .");if(e().toLowerCase().endsWith(".jpg") || e().toLowerCase().endsWith(".jpeg")){ImageResizer resizer = new ImageResizer(1024, 720);//n("Resized> " + path + e());ImageWithTempThubnails(path + fileName);}} catch (Exception ex) {n("Error: Cannot save multimedia files!");tance().createNewLog("ERROR: Cannot upload multimedia files for user " +sion().getAttribute("username") + " ");}}}//Show result page.//uestDispatcher("").forward(request, response);}开发者ID:lp190zn,项⽬名称:gTraxxx,代码⾏数:60,⽰例13: getFileParameterValue点赞 2import em; //导⼊⽅法依赖的package包/类/*** Responsible for constructing a FileBean object for the named file parameter. If there is no* file parameter with the specified name this method should return null.** @param name the name of the file parameter* @return a FileBean object wrapping the uploaded file*/public FileBean getFileParameterValue(String name) {final FileItem item = (name);if (item == null|| ((e() == null || e().length() == 0) && e() == 0)) {return null;}else {// Attempt to ensure the file name is just the basename with no path includedString filename = e();int index;if (WINDOWS_PATH_PREFIX_r(filename).find())index = dexOf('');elseindex = dexOf('/');if (index >= 0 && index + 1 < () - 1)filename = ing(index + 1);// Use an anonymous inner subclass of FileBean that overrides all the// methods that rely on having a File present, to use the FileItem// created by commons upload new FileBean(null, tentType(), filename, t) {@Override public long getSize() { return e(); }@Override public InputStream getInputStream() throws IOException {return utStream();}@Override public void save(File toFile) throws IOException {try {(toFile);delete();}catch (Exception e) {if (e instanceof IOException) throw (IOException) e;else {IOException ioe = new IOException("Problem saving uploaded file.");use(e);throw ioe;}}}@Overridepublic void delete() throws IOException { (); }};}}开发者ID:nkasvosve,项⽬名称:beyondj,代码⾏数:55,⽰例14: insert点赞 2import em; //导⼊⽅法依赖的package包/类private OBError insert(VariablesSecureApp vars, String strFileReference, String tableId,String key, String strDataType, String strText, String documentOrganization)throws IOException, ServletException {String cFileId = strFileReference, fileDir = null, path = null;OBError myMessage = null;myMessage = new OBError();le("");if (gEnabled())("Deleting records");Connection conn = null;fileDir = getAttachmentDirectoryForNewAttachments(tableId, key);try {conn = nsactionConnection();final String inpName = "inpname";String strName = "";final FileItem file = tiFile(inpName);if (file == null)throw new ServletException("Empty file");strName = e();// FIXME: Get the directory separator from Java runtimeint i = dexOf("");if (i != -1) {strName = ing(i + 1);// FIXME: Get the directory separator from Java runtime} else if ((i = dexOf("/")) != -1) {strName = ing(i + 1);}boolean fileExists = false;final TabAttachmentsData[] files = (this, "'" + ent()+ "'", "'" + documentOrganization + "'", tableId, key);for (TabAttachmentsData data : files) {if ((strName)) {fileExists = true;cFileId = d;}}if (!fileExists) {path = getPath(fileDir);// We only insert a new record if there is no record for this (conn, this, cFileId, ent(), documentOrganization,r(), tableId, key, strDataType, strText, strName, path);} else {// We update the existing (this, r(), strDataType, strText, cFileId);}try {// FIXME: Get the directory separator from Java runtimefinal File uploadedDir = new File(Directory + "/" + fileDir);if (!())();final File uploadedFile = new File(uploadedDir, strName);(uploadedFile);// FIXME: We should be closing the file here to make sure that// is closed// and that is does not really get closed when the GC claims the// object (indeterministic)} catch (final Exception ex) {throw new ServletException(ex);}releaseCommitConnection(conn);} catch (final Exception e) {try {releaseRollbackConnection(conn);} catch (final Exception ignored) {}tackTrace();("Rollback in transaction");e("Error");sage(eBD(this, "ProcessRunError", guage()));return myMessage;// return "ProcessRunError";}e("Success");sage(eBD(this, "Success", guage()));return myMessage;// return "";}开发者ID:mauyr,项⽬名称:openbravo-brazil,代码⾏数:81,⽰例15: uploadFile2Folder点赞 2import em; //导⼊⽅法依赖的package包/类/*** 将上传的⽂件放到指定的⽬录下* @param request HttpServletRequest对象* @param sourceFolder 指定⽂件夹* @param fileName 指定⽂件名,包含扩展名(数组)* @return List 返回⽂件名集合* @throws Exception 抛出异常*/public List uploadFile2Folder(HttpServletRequest request,String sourceFolder,String[] fileName)throws Exception{DiskFileItemFactory factory = new DiskFileItemFactory();if(sizeThreshold!=0){eThreshold(sizeThreshold);}if(repositoryPath!=null){ository(new File(repositoryPath));}ServletFileUpload upload = new ServletFileUpload(factory);if(sourceFolder==null){sourceFolder="";}if(sizeMax!=0){eMax(sizeMax);}if(encoding!=null){derEncoding(encoding);}//若指定⽂件加不存在,则创建List list = new ArrayList();File file=new File(sourceFolder);if(!()){();}//开始读取上传信息List fileItems = equest(request);if(fileItems!=null&&()!=0){Iterator it=or();int i=0;while(t()){FileItem fi=(FileItem)();if(!Field()){//忽略其他不是⽂档域的任何表单信息String name=e();String nameDir=name;if(dexOf("")>=0){nameDir=ing(dexOf(""));}String type=null;if(dexOf(".")>=0){type=ing(dexOf(".")+1);}//⾃⼰指定⽂件名if(fileName!=null){if(fileName[i]!=null){nameDir=fileName[i];}i++;}//判断是否设定了上传的⽂件类型if(type!=null&&!isHave(types,type)){File f=new File(sourceFolder+nameDir);(f);(sourceFolder+nameDir);}}}}return list;}开发者ID:thinking-github,项⽬名称:nbone,代码⾏数:70,⽰例16: writeToFile点赞 2import em; //导⼊⽅法依赖的package包/类/*** 将上传的数据流存⼊临时⽂件** @param fileSourcel* 上传流* @param tempFile* 临时⽂件* @throws IOException*/private String writeToFile(HttpServletRequest request) throws IOException {//获取⽹络访问路径String path = textPath();StringBuffer fileUrl = new StringBuffer();(eme()).append("://").append(verName()).append(":").append(verPort()).append(path).append("/files/audio/");File audioDir = new File(ileFolder);if (!()) {();}File tempDir = new File(leFolder);if (!()) {();}try {// Create a factory for disk-based file itemsDiskFileItemFactory factory = new DiskFileItemFactory();// Set factory eThreshold(4096); // 设置缓冲区⼤⼩,这⾥是ository(tempDir);// 设置缓冲区⽬录// Create a new file upload handlerServletFileUpload upload = new ServletFileUpload(factory);// Set overall request size eMax(4194304); // 设置最⼤⽂件尺⼨,这⾥是4MBList items = equest(request);// 得到所有的⽂件Iterator i = or();while (t()) {FileItem fi = (FileItem) ();String fileName = e();if (fileName != null) {File fullFile = new File(e());File savedFile = new File(ileFolder, e());(savedFile);(fileName);}}("===⽂件已上传===");} catch (Exception e) {// 可以跳转出错页⾯("错误原因:" + sage());}return ng();}开发者ID:zhaoyangzhou,项⽬名称:NPush,代码⾏数:60,注:本⽂中的⽅法⽰例整理⾃Github/MSDocs等源码及⽂档管理平台,相关代码⽚段筛选⾃各路编程⼤神贡献的开源项⽬,源码版权归原作者所有,传播和使⽤请参考对应项⽬的License;未经允许,请勿转载。

发布者:admin,转转请注明出处:http://www.yc00.com/web/1688383558a129848.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信