Saving uploaded file in specific location

前端 未结 2 1156
既然无缘
既然无缘 2021-01-05 20:29

I have the following code which handles files upload on the server. But how to save the file to a specific location on the server

import gwtupload.server         


        
2条回答
  •  伪装坚强ぢ
    2021-01-05 20:53

    You should use File#createTempFile() which takes a directory instead.

    File file = File.createTempFile("upload-", ".bin", new File("/path/to/your/uploads"));
    item.write(file);
    

    Or if you actually want to move the temp file to another location afterwards, use File#renameTo().

    File destination = new File("/path/to/your/uploads", file.getName());
    file.renameTo(destination);
    

提交回复
热议问题