zoukankan      html  css  js  c++  java
  • 读取properties 配置文件

    <dependency>
    <groupId>com.github.tobato</groupId>
    <artifactId>fastdfs-client</artifactId>
    <version>1.27.2</version>
    </dependency>

    fastdfs.properties

    ip=192.168.211.132
    port=8888
    import com.github.tobato.fastdfs.domain.fdfs.StorePath;
    import com.github.tobato.fastdfs.service.FastFileStorageClient;
    import entity.Result;
    import entity.StatusCode;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.util.StringUtils;
    import org.springframework.web.bind.annotation.*;
    import org.springframework.web.multipart.MultipartFile;
    
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.UnsupportedEncodingException;
    import java.util.Properties;
    
    @RestController
    @CrossOrigin
    @RequestMapping("/upload")
    public class FileUploadController {
        @Autowired
        private FastFileStorageClient fastFileStorageClient;
        private static String ip;
        private static String port;
    
        static {
            Properties properties=new Properties();
            InputStream inputStream=Object.class.getResourceAsStream("/fastdfs.properties");
            InputStreamReader inputStreamReader=null;
            try {
                 inputStreamReader=new InputStreamReader(inputStream,"GBK");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            try {
                properties.load(inputStreamReader);
            } catch (IOException e) {
                e.printStackTrace();
            }
            ip = properties.getProperty("ip");
            port=properties.getProperty("port");
        }
    
        /**
         * 文件上传
         */
        @PostMapping
        public Result upload(@RequestParam("file") MultipartFile file) throws IOException {
            StorePath storePath = fastFileStorageClient.uploadFile(file.getInputStream(), file.getSize(), StringUtils.getFilenameExtension(file.getOriginalFilename()), null);
            String storePathFullPath = storePath.getFullPath();
            String url = "http://"+ip+":"+port+"/" + storePathFullPath;
            return new Result(true, StatusCode.OK, "上传成功", url);
        }
    
    }

    测试

     

     

     

  • 相关阅读:
    一、cocos2d-x 3.0 final使用httpclient编译到android,须要用到的android.mk
    lvchange的available參数
    基于谱减法的声音去噪
    ios使用openUrl进行应用跳转
    linux下ssh免密登陆
    字体图标 icon font
    hdu 3642 Get The Treasury(扫描线)
    3D游戏引擎一 win32编程
    Codeforces 112B-Petya and Square(实现)
    动态规划 is beginning。。。。。。。。。
  • 原文地址:https://www.cnblogs.com/yscec/p/12996265.html
Copyright © 2011-2022 走看看