is it possible to use utl_file_dir = '*' scope = spfile in 12c Oracle 12c has deprecated  utl_file_dir = '*' scope = spfile,
but I need to use this functionality. Is there any option to do it?

Is it possible to give permission using Java classes?
Deprecated does not mean it can not be used, so yes, you can use it:

[oracle@o71 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Wed Sep 26 15:29:05 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL&gt; alter system set utl_file_dir='*' scope=spfile;

System altered.

SQL&gt;


But keep in mind, it is desupported starting with 18c: Desupport of UTL_FILE_DIR Initialization Parameter, the parameter does not exist anymore.

[oracle@o73 ~]$ sqlplus / as sysdba

SQL*Plus: Release 18.0.0.0.0 - Production on Wed Sep 26 15:28:50 2018
Version 18.3.0.0.0

Copyright (c) 1982, 2018, Oracle.  All rights reserved.


Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.3.0.0.0

SQL&gt; alter system set utl_file_dir='*' scope=spfile;
alter system set utl_file_dir='*' scope=spfile
                                  *
ERROR at line 1:
ORA-02065: illegal option for ALTER SYSTEM


12.2 example:

[oracle@o71 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Thu Sep 27 11:01:50 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL&gt; show parameter utl_file_dir

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
utl_file_dir                         string      *

SQL&gt; !ls -l /home/oracle/hello.txt
ls: cannot access /home/oracle/hello.txt: No such file or directory
SQL&gt; DECLARE
  L_HANDLER UTL_FILE.FILE_TYPE;
BEGIN
  L_HANDLER := UTL_FILE.FOPEN('/home/oracle', 'hello.txt', 'W');
  UTL_FILE.PUTF(L_HANDLER, 'Hello World!');
  UTL_FILE.FCLOSE(L_HANDLER);
END;
/  2    3    4    5    6    7    8

PL/SQL procedure successfully completed.

SQL&gt; !cat /home/oracle/hello.txt
Hello World!