cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing a file

Former Member
0 Kudos

Hi,

I am trying to access a file which is stored within my project itself.

I wouold want to change the contents of the file at runtime. For this i have to access the file .

To access the file i dont want to give an absolute path when it is deployed in the server. How can i get a relative path.

Assuming i am storing this file in the lib folder of the project how will i access it without the absolute path

(I dont want to use http alias!)

Any help is appreciated..

Regards

Bharathwaj

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Bharat,

Try accessing the file by placing in the Mimes directory.

Regards, Anilkumar

Former Member
0 Kudos

Hi Anil,

The problem is when i try to map it to a IFrame source it will take it , if its placed in mimes folder. But when i want to edit its contents i cant do it,because the File class needs a definite path and when i give the file name alone it is taking from <b> server0</b> folder.

So i guess i have to find the relative path.

And also when i use the http alias in

File f = new File("the alias");

its removing the "\".So it ends up like

http:\hostname:port\alias and not as http:
hostname:port\alias.

How to solve this ...!

Regards

Bharathwaj

Former Member
0 Kudos

How about using forward slashes in your URL, like the http protocol defines URL's? The \ is removed because it probably handles it as an escape character.

Former Member
0 Kudos

One of the solution is to use

for
(if I rememeber right)

Former Member
0 Kudos

Hi,

Thanks pascal. But it was not working. I tried this .

http:////localhost:port//somename

and it gave http:/localhost:port/somename.

Dunno why!

I solved it directly.It takes the path till server0 as default .After tat i appended the following

temp
webdynpro
web
local
appname
Components
componentspackage
the file.

Now its reading it.

I wanted a smaller path..But its ok! If anyone comes with better idea plz do share it ! That s y i am opening the question again !

Thanks for the help Anil and Pascal !

Regards

Bharathwaj

Former Member
0 Kudos

If you want to use an http connection so you can use the defined alias, you should use the URLConnection class (java.net.URLConnection) instead of the File class. You can use getInputStream() and getOutputStream() to read/write to the file.

The File class resolves any double /'s or \'s, because they have no meaning in filepaths.

Message was edited by: Pascal Willemsen

Former Member
0 Kudos

Hi Bharathwaj,

have a look at the WDURLGenerator API. This is what you need. You can put your file in the src/mimes/Components/<ComponentName> Folder and then you can access the file like this:


String path = null;
try
{
        WDDeployableObjectPart dop = wdComponentAPI.getDeployableObjectPart();
	path = WDURLGenerator.getResourcePath(dop, "example.txt");
}
catch (Exception e)
{
     // do something
}

File f = new File(path);

Answers (1)

Answers (1)

Former Member
0 Kudos

Please post the soution

Regards, Anilkumar