Reputation: 245
I need to upload .dat file from jsp page. I am using struts. I am using
<input type="file" name="file" size=25 />
in jsp and in action class
FileUploadForm uploadForm = (FileUploadForm) form;
FormFile file = uploadForm.getFile();
InputStream stream = file.getInputStream();
After this I am confused. I dont want to open and read the dat file as the size of the may be big. I just wanna create/copy the same dat file in some specified path in server as per the original name of the dat file. How to do it?
And if there is no other way but read it then also tell me how read and write it to dat file.
Upvotes: 0
Views: 904
Reputation: 80593
These are the tasks you need to complete in order to finish this task:
Here is some pseudo-code, utilizing Apache IOUtils to copy the stream data:
final FormFile formFile = uploadForm.getFile();
final String outPath = "/somerootpath/" + formFile.getFileName();
final OutputStream outStream = new FileOutputStream(outPath);
IOUtils.copy(formFile.getInputStream(), outStream);
IOUtils.closeQuietly(outStream);
Upvotes: 1