Hi,
I want to read a JSON file that is “data-in” folder from a custom java transformer class. I can load the file using absolute path but can someone please let me know know to read the file via relative path? I am not able to figure out the context from class is being executed. Since the project will be executed on server (once I am done development) so need the ability to read from a relative path of the project.
Thanks,
First, I recommend using CustomJavaReader instead of CustomJavaTransformer. Examples in the reader component are tailor made for various reading scenarios.
In CustomJavaReader, you can use this simple syntax:
InputStream in = getInputStream("data-in/myFile.txt")
If you want to use a parameter value in the file path, this is the way:
InputStream in = getInputStream(getGraph().getGraphParameters().getGraphParameter("DATAIN_DIR").getValueResolved(RefResFlag.REGULAR)+"/myFile.txt")
Great thank you!