📄 fileuploadutil.java
字号:
/*
* Created on 2005-8-9
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package web.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
/**
* <p>Title: FileUploadUtil.java</p>
*
* <p>Description: </p>
*
* <p>Copyright: SCUT Copyright (c) 2005</p>
*
* <p>Company: KHC</p>
*
* @author yukizh
*
* @version 1.0
*/
public class FileUploadUtil {
public static void upload(String uploadDir,CommonsMultipartFile file) throws Exception{
File dirPath = new File(uploadDir);
if (!dirPath.exists()) {
dirPath.mkdirs();
}
InputStream stream = file.getInputStream();
if((new File(uploadDir + file.getOriginalFilename()).exists())){
return;
//throw (new Exception(""));
}
OutputStream bos = new FileOutputStream(uploadDir + file.getOriginalFilename());
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.close();
stream.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -