FormFile file=manform.getFile();
String fileName = null;
String pathname=null;
String fileAddre="/uptoService";
try {
InputStream stream = file.getInputStream();
String filePath = request.getRealPath(fileAddre);
File file1 = new File(filePath);
((File) file1).mkdir();
fileName = System.currentTimeMillis()
+ file.getFileName().substring(
file.getFileName().lastIndexOf('.'));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream bos = new FileOutputStream(filePath + "/"
+ fileName);
pathname=filePath+"/"+fileName;
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();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Java文件上传到服务器
最新推荐文章于 2024-04-17 10:29:28 发布