Saving uploaded file in specific location

前端 未结 2 1157
既然无缘
既然无缘 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);
    
    0 讨论(0)
  • 2021-01-05 20:59

    In your java application, you can create file with giving specific path.

    Like; "new File("c:/files/filename)" etc.

    See Java Documents to learn about New IO package's Files class' createFile method.

    0 讨论(0)
提交回复
热议问题