Using tJava for rename of current filename

Highlighted
Five Stars

Using tJava for rename of current filename

For one Talend job, I use the tJava component to replace the name of the current file

Code:

String currentFileName = ((String)globalMap.get("tFileList_1_CURRENT_FILE"));

String newCurrentFileName = null;

String pattern = ((String)globalMap.get("Stichtag"));

String replacement = "20181010";

 

if (currentFileName.contains(pattern)){

 

      newCurrentFileName = currentFileName.replaceAll(pattern, replacement);

      globalMap.put(((String)globalMap.get("tFileList_5_CURRENT_FILE")), newCurrentFileName);

     

}

But if I’ll execute this Job I get an exception:

Exception in component tJava_3

java.lang.NullPointerException

Do you have any ideas, what is wrong?

 

Thanks in advance

Tags (1)

Accepted Solutions
Employee

Re: Using tJava for rename of current filename

That is good news :-)

 

Could you please mark the topic as resolved so that it will help our Talend community members?

 

Warm Regards,

 

Nikhil Thampi

View solution in original post


All Replies
Sixteen Stars TRF
Sixteen Stars

Re: Using tJava for rename of current filename

tJava component is executed before other components for the same subjob. So, depending on your job design (not shared) à npe exception may occurs.
May be tFileCopy should be enough for your case.

TRF
Employee

Re: Using tJava for rename of current filename

Hi,

 

    In first step, you are using tFileList_1_CURRENT_FILE but in later step you are using tFileList_5_CURRENT_FILE.

 

    Could you please print and see the value in the variables to make sure that it is havign right values?

 

Warm Regards,

 

Nikhil Thampi

Five Stars

Re: Using tJava for rename of current filename

Hello,

yes, you are right. It was written by mistake. Now it works fine.

 

Thank you very much.

Employee

Re: Using tJava for rename of current filename

That is good news :-)

 

Could you please mark the topic as resolved so that it will help our Talend community members?

 

Warm Regards,

 

Nikhil Thampi

View solution in original post

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Have you checked out Talend’s 2019 Summer release yet?

Find out about Talend's 2019 Summer release

Blog

Talend Summer 2019 – What’s New?

Talend continues to revolutionize how businesses leverage speed and manage scale

Watch Now

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog