layui上传文件data后台怎么获取

本文环境:windows10、layui2.5.6,本文适用于所有品牌的电脑。

思路:

首先获取原始文件名你,并截取文件名后缀;然后重新命名新文件名;最后判断文件路径是否存在该文件,如果存在则将文件写入即可。

代码示例:

@PostMapping("/json/up")
		public String uploadFujian2( MultipartFile file) {
			System.out.println(file.getSize());
			//readIoStringToFile(file.toString(),"D://test/test.doc");


			if (file != null) {
				try {
					//String fileRealName = file.getOriginalFilename();//获得原始文件名;
					//int pointIndex =  fileRealName.lastIndexOf(".");//点号的位置
					//String fileSuffix = fileRealName.substring(pointIndex);//截取文件后缀
					//String fileNewName = DateUtils.getNowTimeForUpload();//新文件名,时间戳形式yyyyMMddHHmmssSSS
					//String saveFileName = fileNewName.concat(fileSuffix);//新文件完整名(含后缀)
					String filePath  = "D:\\FileAll" ;
					File path = new File(filePath); //判断文件路径下的文件夹是否存在,不存在则创建
					if (!path.exists()) {
						path.mkdirs();
					}
					File savedFile = new File(filePath);
					savedFile = new File(filePath,"test.doc");
					// 使用下面的jar包

					FileUtils.copyInputStreamToFile(file.getInputStream(),savedFile);
					boolean isCreateSuccess = savedFile.createNewFile(); // 是否创建文件成功
					if(isCreateSuccess){      //将文件写入
						//第一种
						//file.transferTo(savedFile);
						//第二种

					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}else {
				System.out.println("文件是空的");
			}



			//IOUtils.read(file)
			//File dest = new File("");
			return "ok";
		}

以上就是layui上传文件data后台怎么获取的详细内容,更多请关注本赛季网其它相关文章!

赞(0) 打赏
未经允许不得转载:本赛季网首页 » Layui 教程

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

Tian开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏