To write a txt/xml file to Service Export and directory:
In this post, we will see how to create text file using java code in the "\StaticContent\global\ServiceExport" directory.
In step -1: Page new to create a new page for holding the data to be written in the text file.
In step -2: setting the paramters for file name and then xml string or data.
In step -3 below java code need to be added to create text file, in this case XML file is being generated.
java.io.OutputStream outStream = null;
try {
//Whatever the file path is.
//String strFileName="Example_Pega12.xml";
String pathname = tools.findPage("pxProcess").getProperty("pxServiceExportPath").getStringValue() + PRFile.separatorChar + strFileName;
//java.io.File statText = new java.io.File("C:\\Softwares\\examplePega.txt");
PRFile file = new PRFile(pathname);
PROutputStream fileStream = new PROutputStream(file);
outStream = new java.io.BufferedOutputStream(fileStream);
byte[] outBytes=StrData.getBytes();
//byte buffer2[] = new byte[4096];
outStream.write(outBytes);
outStream.flush();
outStream.close();
}catch (java.io.IOException ioEx) {
oLog.error("Error writing uploaded file to local storage", ioEx);
}
In step 4- @baseclass DownloadFile activity and passing the stringFile name as parameter which we created in step 3, that in turn will have java code to download the file to the browser.
You can try and let us know the comments.
In this post, we will see how to create text file using java code in the "\StaticContent\global\ServiceExport" directory.
In step -1: Page new to create a new page for holding the data to be written in the text file.
In step -2: setting the paramters for file name and then xml string or data.
In step -3 below java code need to be added to create text file, in this case XML file is being generated.
java.io.OutputStream outStream = null;
try {
//Whatever the file path is.
//String strFileName="Example_Pega12.xml";
String pathname = tools.findPage("pxProcess").getProperty("pxServiceExportPath").getStringValue() + PRFile.separatorChar + strFileName;
//java.io.File statText = new java.io.File("C:\\Softwares\\examplePega.txt");
PRFile file = new PRFile(pathname);
PROutputStream fileStream = new PROutputStream(file);
outStream = new java.io.BufferedOutputStream(fileStream);
byte[] outBytes=StrData.getBytes();
//byte buffer2[] = new byte[4096];
outStream.write(outBytes);
outStream.flush();
outStream.close();
}catch (java.io.IOException ioEx) {
oLog.error("Error writing uploaded file to local storage", ioEx);
}
In step 4- @baseclass DownloadFile activity and passing the stringFile name as parameter which we created in step 3, that in turn will have java code to download the file to the browser.
You can try and let us know the comments.
This post is very simple to read and appreciate without leaving any details out. Great work ! Call center Software Solution
ReplyDelete