Java DiskFileUpload类使用实例

发布时间:2025-12-09 12:03:40 浏览次数:2

实例1: finishUpload

import io.netty.handler.codec.http.multipart.DiskFileUpload; //导入依赖的package包/类private String finishUpload() throws Exception {    String pathTo = null;    try {        while (decoder.hasNext()) {            InterfaceHttpData data = decoder.next();            if (data != null) {                if (data instanceof DiskFileUpload) {                    DiskFileUpload diskFileUpload = (DiskFileUpload) data;                    Path tmpFile = diskFileUpload.getFile().toPath();                    String uploadedFilename = diskFileUpload.getFilename();                    String extension = "";                    if (uploadedFilename.contains(".")) {                        extension = uploadedFilename.substring(uploadedFilename.lastIndexOf("."),                                uploadedFilename.length());                    }                    String finalName = tmpFile.getFileName().toString() + extension;                    //this is just to make it work on team city.                    Path staticPath = Paths.get(staticFolderPath, uploadFolder);                    if (!Files.exists(staticPath)) {                        Files.createDirectories(staticPath);                    }                    Files.move(tmpFile, Paths.get(staticFolderPath, uploadFolder, finalName),                            StandardCopyOption.REPLACE_EXISTING);                    pathTo =  uploadFolder + finalName;                }                data.release();            }        }    } catch (EndOfDataDecoderException endOfData) {        //ignore. that's fine.    } finally {        // destroy the decoder to release all resources        decoder.destroy();        decoder = null;    }    return pathTo;} 
diskfileupload
需要做网站?需要网络推广?欢迎咨询客户经理 13272073477