cancel
Showing results for 
Search instead for 
Did you mean: 

reading text file from client machine on NW04

Former Member
0 Kudos

Hi There,

We need to read a text file from a fixed location to our WD application. need to read this text file content in a String and use it further.

We are on NW04 and so none of WDResource stuff will work for us :-(.

i tried this piece of code:

byte[] file_data_in_bytes = null;

//Get the selected file's contents in a byte array. returns null if no file is selected.

file_data_in_bytes = wdContext.currentContextElement().getCtx_va_FileData();

but file_data_in_bytes is null .. have attached contect variable Ctx_va_FileData to data property of upload UI.

Have i have missed out something.

Thanks for your time.

Rgds

Accepted Solutions (1)

Accepted Solutions (1)

Saravanan_SD
Advisor
Advisor
0 Kudos

Hi Sudhir,

Value attribute Ctx_va_Filedata must be of type Binary. Map this attribute to the fileupload UI datasource and try accessing it as wdcontext.currentcontextelement.get Ctx_va_Filedata.

Hope it is helpful.

Regards,

Saravanan

Former Member
0 Kudos

I am using

ByteArrayInputStream byteArrayInputStream =

new ByteArrayInputStream(file);

Reader reader = new InputStreamReader(byteArrayInputStream);

line_of_file = bufferedReader.readLine();

Saravanan_SD
Advisor
Advisor
0 Kudos

Hi Sudhir,

You should pass the bytes[] into the ByteArrayInputStream. Could you explain what exactly you are trying to implement?

For uploading file from the fixed path, it would be necessary to use file = new file(path). This path would be not from the local PC but from the Server where it is deployed. Evne I have tried doing the same. I would also like to wait for others ideas on this.

Regards,

Saravanan.

Former Member
0 Kudos

Hi,

Try out the following function


private void  setByteArrayFromResourcePath(String resourcePath)
  throws FileNotFoundException, IOException {
  FileInputStream in = new FileInputStream(new File(resourcePath));
  byte[] part = new byte[10 * 1024];
  ByteArrayInputStream out = new ByteArrayInputStream(part);
  int length;
  while ((length = in.read(part)) != -1) {
  out.read(part, 0, length);
  }
  in.close();
  }

Regards

Ayyapparaj

Former Member
0 Kudos

Hi Saravanan,

I am trying to read a text file and need to pass its content to RFC.

Now this text file is generated by a script and is created with particular name and location.. i wanted to read this file and pass content to RFC.

You are right, as so far i could find a solution to autopick from client machine.

Rgds

Former Member
0 Kudos

Hi Ayyapparaj,

which variable will hold value of content in the file... and what will be format for file path here..(hope this will pick client's machine location not server one).

Rgds

Former Member
0 Kudos

Hi Guys..

Anyone has any idea on this.. what could be missing here.

Rgds

Answers (2)

Answers (2)

Former Member
0 Kudos

Former Member
0 Kudos

Hi,

Data type should be of type Binary.

Pl go through this tutorial for NW04

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/202a850a-58e0-2910-eeb3-bfc3e081...

Regards,

Ayyapparaj

Former Member
0 Kudos

Thanks a lot for your reply... I am using Binary data type only for reading it.

when i debugged the application. i saw condition

while ((line_of_file = bufferedReader.readLine()) == null)

is failing and thats why none of the value is being passed... is there something missing in this syntax..

Also if is possible to read a file from particular location, i.e. instead of use selecting a file though Upload UI, can we default the file location and upload it same way?

Regards,

Sudhir

Former Member
0 Kudos

Hi Sudhir,

Replace,

while ((line_of_file = bufferedReader.readLine()) == null)

with

while ((line_of_file = bufferedReader.readLine()) != null)

i.e if line_of_file contains Data, continue.

Hope it Helps.

Regards,

Alka.