Discussion

File creation problem

Hi,

I able to create the xls files in serviceexport floder by using PRFile, but i want to create that file in PRWeb folder.i am attached the sample code wat i wrote. Can any one help me how to stores the files in PRWEB folder.

//##############SAMPLE CODE#################

StringBuffer strData = new StringBuffer("<HTML><TABLE width='100%' border='1'>");
strData.append("<TR>");
strData.append("<TR><TD colspan=9 bgColor='#dcdcdc'>"+"ReportHeader"+":" + " </TD></TR>");
strData.append("<TR><TD></TD></TR>");
strData.append("</TABLE></HTML>");
String fileName = "Test";
String pathName="/";
PRFile writefile = new PRFile(pathName + fileName + ".xls");
try {
PRWriter writer = new PRWriter(writefile, PRFileUtil.ENCODING_UPLOAD);
writer.write(strData.toString());
writer.close();
} catch (java.io.IOException ioEx) {
oLog.error(StringUtils.concat(StringUtils.ASIS,"Couldn't write file " , writefile), ioEx);
}
//###############################

Thanks,
Channa

**Moderation Team has archived post**

This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.

Comments

Keep up to date on this post and subscribe to comments

March 13, 2009 - 10:51am

Channa, is there a specific reason why you want the xls in prweb folder?
In my project, we generate about 200 xls files in ServiceExport directory. We then have a Download file link from one of sections for users to download the xls from ServiceExport. It is working fine for the business.

July 15, 2009 - 10:44am

Hi Channa,

I also have to do the save a file on the server but PRFile does not take file name in the constructor(only takes the target directory structure). It gives the below error:

A parameter must be a directory

Not sure how it worked in your case...??

I am using PRPC v5.4 SP2.

thanks in advance.
Amit

Pega
July 16, 2009 - 3:08am

after writing in service export, copy and write(through file copy) it in prweb then delete the origional one.

Regards,
Sankar

July 16, 2009 - 3:07pm

Simply use nromal FileWrite. You can write whereever you want.

StringBuffer strData = new StringBuffer("<HTML><TABLE width='100%' border='1'>");
strData.append("<TR>");
strData.append("<TR><TD colspan=9 bgColor='#dcdcdc'>"+"ReportHeader"+":" + " </TD></TR>");
strData.append("<TR><TD></TD></TR>");
strData.append("</TABLE></HTML>");
String fileName = "/Test";
String pathName="/opt/WebSphere/AppServer/installedApps/SERVERNAME/prpc_dev.ear/prweb.war"; // FOR EXAMPLE
// FULL DIRECTORY STRUCTURE

java.io.FileWriter fstream = new java.io.FileWriter(pathName+ fileName+".xls");
java.io.BufferedWriter out = new java.io.BufferedWriter(fstream);
out.write(strData.toString());
out.close();

PRFile is also internally going to create code like this only.

July 16, 2009 - 3:15pm

Hi Lingasamy,

Out.write won't write stuff on the pega server.
You need to use pega wrapper classes like PRWriter or PROutputStream to write on the server through a code in your activity.

Thanks,
Amit

July 16, 2009 - 3:19pm

To answer as best as I can according to J2EE -- java.io.FileWriter is not guaranteed to work on every server with every configuration (you might need to set up file permissions, etc.). PRFile, on the other hand, is guaranteed work on J2EE, and that's why it's recommended.

Yes, obviously, you still have the business problem of trying to copy files outside the container.

Jon

July 20, 2009 - 11:43am

If PRFile & PRWrite is going to work on one system, Surely java.io.FileWriter or java.io.FileOutputStream should work.
I am sure PRWrite is extended / using java.io.File or java.io.Writer or java.io.FileWrite or java.io.FileOutputStream. I do not think PRWrite classes can achieve io operation without using java.io class.
If PRFile is restricting the location, I do no think we have a best solution other than using normal java code.

July 20, 2009 - 1:05pm

Lingasamy wrote: I am sure PRWrite is extended / using java.io.File or java.io.Writer or java.io.FileWrite or java.io.FileOutputStream. I do not think PRWrite classes can achieve io operation without using java.io class.

Yes, when deployed on Tomcat or Websphere this I believe this is the case. But it's possible to deploy a J2EE app on a server that doesn't use a file system.

I can't give the official Pega response to this conundrum, but I did find a 2003 blog post which summarizes the issues about file access in J2EE. The nut of this is that the EJB spec asserts a general business reason ("The file system APIs are not well-suited for business components to access data...") and it's often the business users who ask for data to be written directly to files. Still, writing to a content management system is often the best solution.

Jon

July 21, 2009 - 1:37pm

Thanks Jon. It makes sense.

December 17, 2009 - 1:00pm

quote:


Originally posted by SHIVAPRT
In my project, we generate about 200 xls files in ServiceExport directory. We then have a Download file link from one of sections for users to download the xls from ServiceExport. It is working fine for the business.

Shiva,

I am trying to open an excel file from temp directory and read it. Are you using PRFile in your application to read an excel? I was able to read csv and xml file with PRFile. Since PRFile doesn't support xls (excel) files, I had to use "File" API to open the xls file in my java method.

Could you give me more details on how you are downloading from service export directory?

Note: When i am using "File" API, I had to give full temp path "/usr/IBM/WebSphere/AppServer/profiles/Pega_dev_cl/temp/laadws22Node04/pega_2_ws22/prweb_cl_sp3_war/prweb.war/StaticContent/global/ServiceExport/try.xls", since "file://web:/StaticContent/global/ServiceExport/" is throwing "No such file or directory" with File API. Also the temp path varies for different nodes in the server, hence i should dynamically build the temp path. Moreover, any suggestion for getting the temp path dynamically will be most helpful.

Thanks,
Padma.

March 31, 2009 - 8:59pm

Hi Shiva,

Hear the prob is every weekend the server maintance team deleted all Temporary files from sysmanagement, it is automatically deleted all files under service export floder, that's way we are planning to change the file storage location.