cancel
Showing results for 
Search instead for 
Did you mean: 

Temp text file at runtime

0 Kudos

Hello experts,

Can i create a temp file in a WD Project and then read and modify it at runtime.

If possible can you please tell me how this can be done

Thanks and Regards,

G. Singh

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

What exactly is your use case?

You could place the file inside src/mimes/components/<component> and read/modify it at runtime.

Armin

0 Kudos

Hello Armin,

I want to .txt file.

I tried to create it in src/mimes/components/<component> but didn't suceed.

Can you please tell me what i need to do exactly ??

Is there any article or blog explainnig this ??

Thnaks and Kind Regards,

Gursimran Singh

Former Member
0 Kudos

Hi,

You can use . properties file in project, to read data. but you are not able to edit data in the project files.

If you create any temp.txt in server0 location . and you can edit from there.

see this below code

// this code create temp.txt file in server location \usr\sap\j2ee\jcxx\j2ee\cluster\server0

FileWriter write=new FileWriter("temp.txt");

Regards,

Naga

0 Kudos

Hello Naga,

This doesnot create file if i have no rights on the server.

That is the reason i want to use my own project for creating the temporary text file.

Regards,

Gursimran Singh.

Former Member
0 Kudos

Hi,

You can use Km to create and update files.

There is no possibility to update files from project without using file system.

Regards,

Naga

Former Member
0 Kudos

Hi,

Use

String fileName = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(),"file.txt");

File file = new File(fileName);

Regards

Ayyapparaj

0 Kudos

Hello Naga,

That i exactly what i want.

Can you please explain how to do that

Can you please refer some article or blog ??

Kind Regards,

Gursimran Singh

0 Kudos

Hello Naga,

According to the documents i have written the below code, but still i am unable to create a .txt file at the given location.

ResourceContext resourceContext = buildResourceContext();

//get a resource factory

IResourceFactory resourceFactory = ResourceFactory.getInstance();

//Get a RID from the current path to display

RID pathRID = RID.getRID("/userhome/" + ep5User.getDisplayId()+ "/favorites");

//Get a Iresource object to work on

IResource resource = resourceFactory.getResource(pathRID, resourceContext);

ICollection folder = (ICollection) resourceFactory.getResource(pathRID,buildResourceContext());

folder.createResource("test.txt",null);

Can you please suggest something??

Kind Regards,

Gursimran Singh

Former Member
0 Kudos

Hi

use this below code and add the Sharing reference to ur wdp project PORTAL:sap.com/com.sap.km.application

try {

// get ep5 User

IWDClientUser wdClientUser = WDClientUser.getCurrentUser();

com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();

com.sapportals.portal.security.usermanagement.IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);

//create resource context

IResourceContext resourceContext = new ResourceContext(ep5User);

//get a resource factory

IResourceFactory resourceFactory = ResourceFactory.getInstance();

//Get a RID from the current path to create

RID pathRID = RID.getRID("/userhome/" + ep5User.getDisplayId()+ "/favorites");//make sure this directory already exist

// Get a Iresource object to work on

IResource resource = resourceFactory.getResource(pathRID, resourceContext);

//get the collection

ICollection collection = (ICollection) resource;

//creating content

String strs=" test file";

ByteArrayInputStream bbr=new ByteArrayInputStream(strs.getBytes());

IContent content=new Content(bbr,"text/plain",strs.length());

//create resource

collection.createResource("test.txt",null,content);

} catch (NotSupportedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (AccessDeniedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (WDUMException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (ResourceException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (UserManagementException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Former Member
0 Kudos

Do you need something like a .properties file? Could you explain in more detail what kind of file you need? What its supposed to be stored in there?

Regards.

Julio Herrera

Former Member
0 Kudos

Hi,

Have you try it with BufferedReader?

Regards,

Arnau Rovira