This question might be asked many times, but I did not find a direct answer.
Actually I am using WebSphere for running my Java web application, I wanted to save/store m
Below is code for uploading files in struts 1.x
public class MyModel extends ActionForm {
private static final long serialVersionUID = 1L;
private FormFile file = null;
public void setFile(FormFile file) {
this.file = file;
}
public FormFile getFile() {
return this.file;
}
}
public class FileUploadAction extends DispatchAction{
MyModel m = (MyModel) form;
FormFile myFile = m.getFile();
String contentType = myFile.getContentType();
String fileName = myFile.getFileName();
int fileSize = myFile.getFileSize();
byte[] fileData = myFile.getFileData();
String recieveMaterialFileName = myFile.getFileName();
File newFile = new File("D:/resources/images", recieveMaterialFileName);
if(!newFile.exists()){
FileOutputStream fos = null;
try {
fos = new FileOutputStream(newFile);
fos.write(myFile.getFileData());
fos.flush();
} catch (FileNotFoundException e) {
System.err.println("Error " + e);
} catch (IOException e) {
System.err.println("Error " + e);
}finally{
fos.close();
}
}
}