在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ java后臺上傳圖片的controller,什么錯誤都沒有報,但路徑下就是沒有生

java后臺上傳圖片的controller,什么錯誤都沒有報,但路徑下就是沒有生成圖片?

@RequestMapping(value = "/upload_img",method = {RequestMethod.GET, RequestMethod.POST},produces = "application/json; charset=utf-8")
    @ResponseBody
    
    public String upload_img(MultipartFile file,HttpServletRequest request) throws Exception{
        
        String path="/upload/news";
        
        //創(chuàng)建文件 
        File dir=new File(path);
        if(!dir.exists()){
            dir.mkdirs();
        }
        
        String id = SysUtil.getUUID();
        String fileName=file.getOriginalFilename();
      
    
        String img=id+fileName.substring(fileName.lastIndexOf("."));//zhao.jpg
        FileOutputStream imgOut=new FileOutputStream(new File(dir,img));//根據(jù) dir 抽象路徑名和 img 路徑名字符串創(chuàng)建一個新 File 實例。
        
        imgOut.write(file.getBytes());//返回一個字節(jié)數(shù)組文件的內(nèi)容
        imgOut.close();
        Map<String, String> map=new HashMap<String, String>();
        map.put("path",img);
        return JSON.toJSONString(map);
    }
回答
編輯回答
萌二代

打印調(diào)試法:

在寫文件前后打控制臺輸出,寫圖片換成寫個 txt 看一下結(jié)果。

2018年7月2日 23:33
編輯回答
壞脾滊

確認(rèn)下路徑的權(quán)限問題。

看了你另一個問題,你是在win操作系統(tǒng)運行,然后使用linux系統(tǒng)的路徑。
em...多理解下路徑吧

2017年7月26日 16:34