cancel
Showing results for 
Search instead for 
Did you mean: 

How to read text file content in portal application?

Former Member
0 Kudos

Hi,

How do we read text file content in portal application?

Can anyone forward the code to do do?

Regards,

Anagha

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Are you reading the file from KM? Where the file is stored?

Regards,

Yoga

Former Member
0 Kudos

Hi,

Actually I want to read content from text file and display it as marque. File stored in KM is preferable.

Anagha

Former Member
0 Kudos

Check the code below. This help you to know how to read the text file content line by line. You can display as you require.

IUser user = WPUMFactory.getServiceUserFactory().getServiceUser("cmadmin_service");

IResourceContext resourceContext = new ResourceContext(user);

String filePath = "/documents/....";

RID rid = RID.getRID(filePath);

IResource resource = ResourceFactory.getInstance().getResource(rid,resourceContext);

InputStream inputStream = resource.getContent().getInputStream();

BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

String line = reader.readLine();

while(line!=null) {

line = reader.readLine();

//You can append in string buffer to get file content as string object//

}

Regards,

Yoga

Former Member
0 Kudos

If you decide not to use KM, then there is a portal component here (https://wiki.sdn.sap.com/wiki/display/Snippets/Portalcomponenttoshowatextfile) which allows fro presenting a text file from the portal file system.

Former Member
0 Kudos

Getting an error when I import

"import javax.servlet.http.HttpServletResponse;"

Former Member
0 Kudos

This lives in servlet.jar. It should be on your portal server.

Former Member
0 Kudos

Hi Michael,

I am still stuck up. Not sure where my file would be placed?

Regards,

Anagha

Former Member
0 Kudos

By default I read from file.txt in the top level folder of the portal server. So, on a Windows server where the portal is installed on d:, it will be the file d:\file.txt.

You can vhange this value when you make an iView from the component.

Answers (0)