「javassh上传文件」ssh框架文件上传
今天给各位分享javassh上传文件的知识,其中也会对ssh框架文件上传进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、java ssh实现微信端操作 有图片上传的地方 怎么能在上传到服务器之前进行等比例压缩
- 2、Java通过SSH获取Linux文件出错
- 3、在Java项目中上传图片时如何使上传的图片自动保存到指定路径
java ssh实现微信端操作 有图片上传的地方 怎么能在上传到服务器之前进行等比例压缩
public class struts2UploadAction extends ActionSupport {
private File uploadFile;// 得到上传的文件
private String uploadFileContentType;// 得到文件的类型
private String uploadFileFileName;// 得到文件的名称
public String load() throws IOException {
String RealPath = ServletActionContext.getServletContext().getRealPath("/piction");
File file = new File(RealPath);
if(!file.exists()){
file.mkdirs();
}
FileUtils.copyFile(uploadFile, new File(file,uploadFileFileName));
String path=RealPath+"/"+uploadFileFileName;
ServletActionContext.getRequest().setAttribute("realpath",path);
return "success";
}
public File getUploadFile() {
return uploadFile;
}
public void setUploadFile(File uploadFile) {
this.uploadFile = uploadFile;
}
public String getUploadFileContentType() {
return uploadFileContentType;
}
public void setUploadFileContentType(String uploadFileContentType) {
this.uploadFileContentType = uploadFileContentType;
}
public String getUploadFileFileName() {
return uploadFileFileName;
}
public void setUploadFileFileName(String uploadFileFileName) {
this.uploadFileFileName = uploadFileFileName;
}
}
Java通过SSH获取Linux文件出错
1
ssh
在cygwin中执行:$
ssh
username@remotehost
2
scp
命令scp基于ssh协议,可以将本地文件拷贝到远程服务上的指定目录
在Java项目中上传图片时如何使上传的图片自动保存到指定路径
用struts也可以实现 多文件上传
下面是我写的代码,
参数中有要保存的目录
作为参考!
/*文件目录*/
public static String [] fileArray={
"logo.png",
"index.swf",
"OEMInfo.txt",
"favicon.ico"};
/**
* @author Caoshun
* @see 接收并保存文件
* */
public static void receiveAndSaveAllFileByPath(ActionForm form,String rootPath1,String rootPath2){
String fileName="";
//获取表单中的文件资源
HashtableObject, Object files = form.getMultipartRequestHandler().getFileElements();
//遍历文件,并且循环保存
//当前处理文件序号
int file_num=1;
for (EnumerationObject e = files.keys(); e.hasMoreElements();) {
/*根据处理的当前文件下标,确定文件名*/
fileName=fileArray[file_num-1];
FormFile file = (FormFile) files.get((String) e.nextElement());
if (file != null file.getFileSize() 0) {
try {
//使用formfile.getInputStream()来获取一个文件的输入流进行保存。
//文件名
//String fileName = file.getFileName();
//System.out.println("debug in AddEnterpriceAction.java on line 152 fileName is : "+fileName);
//文件大小
//int fileSize = file.getFileSize();
//文件流
InputStream is = file.getInputStream();
//将输入流保存到文件
//String rootPath = this.servlet.getServletContext().getRealPath("files");
//往cn中写入
File rf = new File(rootPath1);
FileOutputStream fos = null;
fos = new FileOutputStream(new File(rf, fileName));
byte[] b = new byte[10240];
int real = 0;
real = is.read(b);
while (real 0) {
fos.write(b, 0, real);
real = is.read(b);
}
//往en中写入
File rf2 = new File(rootPath2);
InputStream is2 = file.getInputStream();
FileOutputStream fos2 = null;
fos2 = new FileOutputStream(new File(rf2, fileName));
byte[] b2 = new byte[10240];
int real2 = 0;
real2 = is2.read(b2);
while (real2 0) {
fos2.write(b2, 0, real2);
real2 = is2.read(b2);
}
//关闭文件流
fos.close();
is.close();
fos2.close();
is2.close();
} catch (RuntimeException e1) {
e1.printStackTrace();
} catch (Exception ee) {
ee.printStackTrace();
}
file.destroy();
}
file_num++;
}
}
关于javassh上传文件和ssh框架文件上传的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-11-28,除非注明,否则均为
原创文章,转载请注明出处。