// FormFile
Class parentClass = Class.forName("org.apache.struts.upload.CommonsMultipartRequestHandler");
Class childClass = parentClass.getDeclaredClasses()[0];
Constructor c = childClass.getConstructors()[0];
c.setAccessible(true);
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(1000 * 1000 * 10);
factory.setRepository(new File("E:\\aa.txt"));
FileItem fileitem = factory.createItem("uploadfile", "application/txt", false, "E:\\aa.txt");
try{
FileInputStream fis = new FileInputStream(new File("E:\\aa.txt"));
InputStreamReader inStream = new InputStreamReader(fis);
OutputStream outStream = fileitem.getOutputStream();
char[] charBuff = new char[1024];
byte[] byteBuff = new byte[1024];
while(inStream.read(charBuff) != -1){
for(int i = 0; i < 1024; i++){
byteBuff[i] = (byte)charBuff[i];
}
outStream.write(byteBuff);
} outStream.flush();
inStream.close();
}catch(Exception e){
e.printStackTrace();
}
FormFile file = (FormFile)c.newInstance(new Object[]{fileitem}); c.setAccessible(false);
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货