|
楼主 |
发表于 2012-11-5 13:50:56
|
显示全部楼层
新增action,参数类型选择object
action定义如下
在java中将输入流存为文件,代码如下- public static String uploadFile(InputStream uploadFile, String str) {
- System.out.println("字符串参数为:" + str);
- String name = java.util.UUID.randomUUID().toString();
- File file = new File(getTempDir() + "/" + name + ".tmp");
- if (file.exists())
- file.delete();
- FileOutputStream output;
- try {
- output = new FileOutputStream(file);
- try {
- byte[] bs = new byte[1024*4];
- int i = -1;
- while ((i = uploadFile.read(bs)) != -1) {
- output.write(bs, 0, i);
- }
- output.flush();
- System.out.println("文件名:" + file.getName());
- } finally {
- output.close();
- }
- } catch (Exception e) {
- throw new RuntimeException("上传失败!", e);
- }
- return "abc";
- }
- private static String getTempDir() {
- return System.getProperty("java.io.tmpdir");
- }
复制代码 |
|