cancel
Showing results for 
Search instead for 
Did you mean: 

How can I write some informations in a text file ?

Former Member
0 Kudos

Hello.

I am a beginner in java in general and in Web Dynpro Java in particular.

I have to work in an application written by a consultant wich works no more at my office.

Due to performances problems (slowness of the application at unpredictable instants),

I have to write in an external file all the actions which make the users in the application.

The problem is I don't know how to proceed.

Somebody can help me ?

Edited by: Serge L. on Aug 10, 2009 2:21 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi serge,

U need to write some information into text file from webdynpro java application.For that.Try this.

1. Place the text file (say "test.txt") under the src/mimes/Components/<full dot-delimited path to your component>. For example, it might look like src/mimes/Components/com.demo.test.something.

//use this code to write data into file

2.String filePath = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(), "test.txt");

File txtFile = new File(filePath);

Writer output = null;

//assume ur information is in context attr.

String str=wdContext.currentContextElement.get<attrname>;

output = new BufferedWriter(new FileWriter(txtFile));

output.write(str);

output.close();

Regards,

Srikanth

Answers (3)

Answers (3)

Former Member
0 Kudos

Ravindra,

As you ask for, here is an additional explanation.

I would like (for instance) to record in an external file the during time of a function.

1. I record the hour before and after the call.

2. I make a subtraction.

3. I write the result on the screen.

This is a part of my code:

long debut = System.currentTimeMillis();

wdContext.currentZ_Rfc_Pda_Get_Next_Item_Pl_InputElement().modelObject().execute();

long fin = System.currentTimeMillis();

long duree = fin - debut;

mgr.reportSuccess("duree = " + duree);

In place of write the result on the screen I want write it in a file.

Srikanth and Swati,

Thank you for your responses.

I am going to make some tests and I inform you of the result

Regards.

Serge.

Former Member
0 Kudos

Hi Serge,

You can try this as well to generate a text file.

Use Filedownload UI element. And try following code in Webdynpro.....

IOUtil IOUtil=new IOUtil();

File f = new File("skill_master.txt");

FileWriter fw = new FileWriter(f);

fw.write(formattedStr);

fw.close();

InputStream template = new FileInputStream(f);

ByteArrayOutputStream templateSourceOutputStream = new ByteArrayOutputStream();

IOUtil.write(template, templateSourceOutputStream);

IWDCachedWebResource resource=WDWebResource.getWebResource(templateSourceOutputStream.toByteArray(), WDWebResourceType.getWebResourceType( "txt","text/html"));

resource.setResourceName("User.txt");

wdContext.currentContextElement().setVa_FileData(resource);

Here formattedStr is the string which contain all the contents you want in the file. Here Va_FileData attribute is of type com.sap.ide.webdynpro.uielementdefinitions.Resource.

Map this Va_FileData attribute to the Filedownload UI. So that when u click on the FileDownload UI it will generate a txt file.

Hope it helps you.

Regards,

Swati

ravindra_bollapalli2
Active Contributor
0 Kudos

>

> Hello.

>

> I am a beginner in java in general and in Web Dynpro Java in particular.

> I have to work in an application written by a consultant wich works no more at my office.

>

> Due to performances problems (slowness of the application at unpredictable instants),

> I have to write in an external file every actions of application users.

>

> The problem is I don't know how to proceed.

> Somebody can help me ?

could be more specific

like which area u r been strucked ??

what is the applications whre it's been calling

where the application (as u said that slowness of the application) how many services been activated by the service

let me know more clearly we will do it

ravindra