Hello,
I am attempting to create a simple PL/Java function that checks where a file exists or not but I am getting an IO error. Are there any security switches I need to set when creating the PL/Java function or is there anything else I am missing?
Code below...
Many thanks,
Marc :-)
Code:
//Java Code
public class FileExists
{
public static boolean checkFile (String input) throws Exception
{
String errorMessage;
try
{
// Check file exists and pass the value back thru the OUT paramenter
File f = new File(input);
return (f.exists());
}
catch (SecurityException ioe)
{
errorMessage = ioe.getMessage();
throw new Exception( errorMessage + " FAILED" );
}
}
}
-- PL/Java Wrapper Fuction
CREATE FUNCTION fileexists(character varying) RETURNS boolean
LANGUAGE java
AS $$FileExists.checkFile(java.lang.String)$$;
--Results
mydb=# select fileexists('/home/postgres/myfile.txt');
ERROR: java.lang.Exception: read on /home/postgres/myfile.txt FAILED