Struts2文件上传,拷贝linux单板
用Struts2做上传功能首先要在struts.xml文件中配置<constant name="struts.multipart.maxSize" value="50000000" />,“struts.multipart.maxSize”这个配置项是上传文件大小限制。如果配置单的值为“50000000",那么上传文件的大小就不能超过“50000000”。如果没有配置那么Struts2默认大小是2M。
下面是代码的实现:
//获取要上传的文件夹中的文件 filepath文件夹路径
File fileThree = new File(filepath);
//删除老的文件
if (fileThree.exists())
{
boolean isFile = fileThree.delete();
}
//获取从前台传过来要上传的文件 strpath文件路径
File newFile = new File(strpath);
//上传文件到存放文件
FileUtils.copyFile(newFile, filepath);
String cmd = "chmod -R 777 " + newFile;
//将文件拷贝到Linux单板
String cmd1 = " scp -r " + strpath+ " media2:"
+ filepath;
String cmd2 = " scp -r " + strpath+ " media1:"
+ filepath;
//执行linux系统命令进行授权和复制
Runtime runtime = Runtime.getRuntime();
runtime.exec(cmd);
runtime.exec(cmd1);
runtime.exec(cmd2);
结束。
下面是代码的实现:
//获取要上传的文件夹中的文件 filepath文件夹路径
File fileThree = new File(filepath);
//删除老的文件
if (fileThree.exists())
{
boolean isFile = fileThree.delete();
}
//获取从前台传过来要上传的文件 strpath文件路径
File newFile = new File(strpath);
//上传文件到存放文件
FileUtils.copyFile(newFile, filepath);
String cmd = "chmod -R 777 " + newFile;
//将文件拷贝到Linux单板
String cmd1 = " scp -r " + strpath+ " media2:"
+ filepath;
String cmd2 = " scp -r " + strpath+ " media1:"
+ filepath;
//执行linux系统命令进行授权和复制
Runtime runtime = Runtime.getRuntime();
runtime.exec(cmd);
runtime.exec(cmd1);
runtime.exec(cmd2);
结束。