上传图片

本地上传 照片 到 服务器 总结 :
第一步 :页面 (<td><input id="imageFile" name="file" type="file"/>)
这里的 类型 为 type name 为 file
第二步后台action:(定义私有变量
private File file; 加上get he set 方法
feeService.saveAccountData(paraMaps ,file);
第三步:
// 上传文件保存 // 文件名称
if (file!=null && StringUtils.isNotEmpty(fiName)) {
File dirFile = new File("/home/mis/transAccount");
if (dirFile.exists() == false) {
dirFile.mkdirs();
}//不存在这个 路径 就创建
File newFile = new File("/home/mis/transAccount" + "/" + fiName);
copy(file, newFile);//写入 输入输出流
cfa.setFileName(fiName);
cfa.setFilePath(FileParamter.tranAccountPath);
}
第四步:
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(src), FileParamter.BUFFER_SIZE);
out = new BufferedOutputStream(new FileOutputStream(dst), FileParamter.BUFFER_SIZE);
byte[] buffer = new byte[FileParamter.BUFFER_SIZE];
while (in.read(buffer) > 0) {
out.write(buffer);
}
} finally {
if (null != in) {
in.close();
}
if (null != out) {
out.close();
}
)

原文地址:https://www.cnblogs.com/lingding/p/11151755.html