cancel
Showing results for 
Search instead for 
Did you mean: 

Reading and writing custom files in a Webdynpro Java

Former Member
0 Kudos

Hi experts!

In the application that i'm developing I need to write a custom file (serialized object) inside a component and read the content inside another component.

I know how to serialize and de-serialize objects, so my question is: can I define the folder where this file goes, like in the same way I can use the mimes folder to store image files? For example: /src/logs/MyFile.dat.

Thanks in advance.

Osvaldo Silva

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Solved the problem using KM to store the serialized file.

I used this code (or something like this):

...

IResource file;

IContent fileContent;

...

// READING

// file contains the reference to the needed KM file

fileContent = file.getContent();

ObjectInputStream ois = new ObjectInputStream(fileContent.getInputStream());

Vector serializedObject = (Vector)ois.readObject();

...

// WRITING

...

// write to server folder

ObjectOutput out = new ObjectOutputStream(new FileOutputStream("server_temp_file"));

out.writeObject(serializedObject);

out.flush();

out.close();

// copy to KM

FileInputStream in = new FileInputStream("server_temp_file");

IContent newfile = new Content(in, "application/octet-stream", -1);

// update

file.updateContent(newfile);

// close streams

in.close();

// delete temp file

File fileToDelete = new File("server_temp_file");

fileToDelete.delete();

...

Hope this can help anyone!

Thanks.

Osvaldo Silva

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Osvaldo

For the purpose you can also use Configuration Adapter API available in NW 7.0/7.1. It allows to store a file in J2EE configuration repository and read it back. Here is you can find some pieces of code:

Configuration Adapter API is located in SAP-JEE/com.sap.engine.client.lib or SAP-JEE/com.sap.engine.deploy.online.

Tell me if you need additional information about the topic.

BR, Sergei

Edited by: Siarhei Pisarenka on Jul 24, 2009 10:59 AM

Former Member
0 Kudos

Hi,

Refer this link,

http://help.sap.com/saphelp_nw04/helpdata/en/ba/78d3c747b24546ab1c1499a054d8a5/content.htm

Refer this blog,

/people/rohit.radhakrishnan/blog/2005/05/27/uploading-files-to-km-repository-using-webdynpro-apis

Regards,

Sunaina Reddy T

Former Member
0 Kudos

Hi,

You can obviously do that, you can create a directory in server and create a file in that directory.

Below is link for Creating A Directory On WAS Server at Desired Location and Uploading File in It Using Web Dynpro for Java.

[https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/607e9392-8167-2b10-b9a8-e0aa297e88c6?overridelayout=true]

Regards

Raghu

Former Member
0 Kudos

Hi,

It is better to use KM APIs for storing file. As far as uploading files from desktop, there are stahdard UI elements in webdynpro.

https://wiki.sdn.sap.com/wiki/display/WDJava/Km%20upload%20using%20Webdynpro%20application?focusedCo...

Regards

Srini