layui文件上傳後臺接收

@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";
		}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章