Reputation:
I have an 3 array of strings ( actually it's an ArrayList ) and I would like to create an InputStream from it, each element of the array being a line in the stream.
String[] business = ['CONSUMER', 'TELUS'];
String[] position = ['Business', 'SMB','THPS'];
String isDone = "Yes";
need to convert the above data into and pass it to InputStream so i can upload the data to ftp server
Business_Unit: 'TELUS', 'CONSUMER'
Position_Group: 'Business', 'SMB', 'THPS'
On-Cycle_Schedule: 'Yes' or 'No
ftp server method as follows
private boolean fileUpload(InputStream isUploadFile, String dirName, String fileName){
boolean storeRetVal = false;
//File submission method
return storeRetVal;
}
the above method gets called from action class
public ActionForward generatePayroll(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
SessionInfoForm _form = (SessionInfoForm) form;
String isDone = "Yes";
String[] business = request.getParameterValues("selectedBusinessValues");
String[] position = request.getParameterValues("selectedPositionValues");
String fileName = "result.csv";
InputStream isUploadFile;
fileUpload(isUploadFile, fileName);
return mapping.findForward("success");
}
Upvotes: 0
Views: 286
Reputation: 4296
You can do something like
String[] business = { "CONSUMER", "TELUS" };
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw);
for (String s : business) {
out.println(s);
}
InputStream in = new ByteArrayInputStream(sw.toString().getBytes());
Upvotes: 0