cancel
Showing results for 
Search instead for 
Did you mean: 

Read/Write text file in UDF

Former Member
0 Kudos

Hi all

I want to import JAR packet in UDF to read and write a text file but i dont know code use in UDF. My java code is this:

-


package mypackage;

import java.io.*;

class LeeFichero {

public static void main(String [] arg) {

File archivo = null;

FileReader fr = null;

BufferedReader br = null;

try {

// Apertura del fichero y creacion de BufferedReader para poder

// hacer una lectura comoda (disponer del metodo readLine()).

archivo = new File ("C://cargap.txt");

fr = new FileReader (archivo);

br = new BufferedReader(fr);

// Lectura del fichero

String linea;

while((linea=br.readLine())!=null)

System.out.println(linea);

}

catch(Exception e){

e.printStackTrace();

}finally{

// En el finally cerramos el fichero, para asegurarnos

// que se cierra tanto si todo va bien como si salta

// una excepcion.

try{

if( null != fr ){

fr.close();

}

}catch (Exception e2){

e2.printStackTrace();

}

}

}

}

-


Best Regards

Accepted Solutions (1)

Accepted Solutions (1)

jyothi_anagani
Active Contributor
0 Kudos

Hi,

You can not directly read the file from C drive or from something. You can read only if it is in FTP .

Use The Below Code. I have tested this. Here I am reading the .txt file.

String temp="";
AbstractTrace trace = container.getTrace();
try
{
      URL url = new URL("ftp://username:password@FtpIPAddress/sender/salary.txt");
      URLConnection yc = url.openConnection();
       yc.connect();

       InputStream in = url.openStream();
       BufferedReader br = new BufferedReader(new InputStreamReader(in));

       temp  = br.readLine();
}
catch( Exception e)
{
      trace.addInfo(e.getMessage());
}

return temp;

Thanks.

Former Member
0 Kudos

Hi all

I need to use Message Mapping to convert the "CF" field (ie 2.00-) to FormaNumber of 18 positions (000000000000002.00) and pass this number to the field "ZBIVTACF" for that BW software can read it, but before I need to eliminate the negative sign that appears to the right of number, I used Message Mapping to fix this but BW marks an error when reads the negative sign in the file.

Another solution would be use UDF to delete characters negatives in the file, but i dont know how put in my UDF to modify the file.

Can you help me ?

Thanks

The format in the original text file is:

-


28/12/08A2720128 1.00 0.84

06/10/09A2720129 8.00 12.65

05/05/09A2720131 14.00 44.26

05/09/09A2720132 1.33 1.11

29/12/08A2720188 2.00- 1.05-

07/09/09A2720253 1.00 1.26

12/11/09A2720254 1.00 2.11

05/12/08A2720297 7.00 14.77

08/12/08A2720300 21.89 32.82

-


Thanks

Edited by: lizcam on Jan 4, 2010 6:29 PM

Former Member
0 Kudos

Hi ,

you can use standard functions and can b done lik this using if then else.

CF(field )-->endswith -


> If -


>ZBIVTACF(target field)

constant

CF(field ) -> replacestring(standard function)->Then-->ZBIVTACF(target field)

constant

constant ()

CF(field )---->Else----->ZBIVTACF(target field)

Former Member
0 Kudos

Thank you Robin thanks thanks... you are king you answer help me very much

Answers (0)