on 2018 Jun 15 11:26 AM
Hi Expert,
I am trying to fetch files from a folder and want to set it in the agreement's attachment tab.
below are the code which does not work for me. Could you please help on this.
String AgrIDName= doc.getDocumentId();
String dirSep = System.getProperty("file.separator");
String AgrAttachFilePath ="D://FTPFolder//sourcing//ExtractData//Dummy//";
File ma1 = new File(AgrAttachFilePath);
if(!ma1.exists()){ ma1.mkdirs();}
File localPath1 = new File(AgrAttachFilePath +"//"+AgrIDName);
if(!localPath1.exists()){
localPath1.mkdirs();
}
File[] listOfFiles = localPath1.listFiles();
attachments = doc.getAttachments();
ParentObjectReferenceIfc parentRef = TypeFactory.createParentObjectReference(doc);
for(int i=0;i<listOfFiles.length;i++)
{
if(listOfFiles[i].isFile()){
String fileName = listOfFiles[i].getName();
File file = new File(localPath1+"//"+fileName);
FileInputStream fis = new FileInputStream(file);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
IOUtils.copy(fis, bytes);
attachBean = attachments.create();
settingAttach= attachBean.getAttachment().setFileData("CCW_v6.01.xls",fis,parentRef,session);
attachBean.setAttachment(settingAttach);
//FileOutputStream fos = new FileOutputStream(file);
//fos.write(bytes.toByteArray());
//fos.flush();
//fos.close();
bytes.close();
fis.close();
}
}
Request clarification before answering.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.