Read/Write a file on the client machine
By francois degrelle on Friday, March 27 2015, 14:58 - PJC - Javabean - Permalink
Purpose
Here is a Java Bean that allows to write/read files on the client machine without installing Webutil.
The Java code
clientfile.java
Register the Bean
The bean must be registered before you can call its methods.
Because the Bean cannot be registered at the very start of the form
(When-New-Form-Instance for example), we need to place this instruction
in a When-Timer-Expired trigger:
When-New-Form-Instance trigger:
DECLARE
timer_id Timer;
BEGIN
timer_id := CREATE_TIMER('bean_timer', 200, NO_REPEAT);
END;
When-Timer-Expired trigger:
FBean.Register_Bean('BL.BEAN_ITEM',1,'oracle.forms.fd.ClientFile');
In my sample dialog, I have a bean area called BEAN_ITEM in the BL block.
The bean is registred, now, so we can invoke its methods:
The methods you can call
Set the filename
FBean.Invoke('BLOCK.ITEM',1,'setFileName','the_file_name
Write the text to this file
FBean.Invoke('BLOCK.ITEM',1,'writeToFile','the_text
Append the text to this file
FBean.Invoke('BLOCK.ITEM',1,'writeAppendToFile','the_text
Read the text from this file
varchar2 := FBean.Invoke_Char('BLOCK.BEAN',1,'readFromFile
Set the log mode to output the Bean messages
FBean.Invoke('BLOCK.ITEM',1,'SetLog
In the sample dialog provided with the article, I use 2 buttons:
- One to write the text:
If :BL.filename is not null Then
-- set the log on --
FBean.Invoke('BL.BEAN_ITEM',1,'SetLog','');
-- set the file name --
FBean.Invoke('BL.BEAN_ITEM',1,'setFileName',:BL.filename);
-- write the text --
FBean.Invoke('BL.BEAN_ITEM',1,'writeToFile','"' || :BL.write || '"');
End if ;
- Another to read the text:
If :BL.filename is not null Then
-- set the log on --
FBean.Invoke('BL.BEAN_ITEM',1,'SetLog','');
-- set the file name --
FBean.Invoke('BL.BEAN_ITEM',1,'setFileName',:BL.filename);
-- read the text from the file --
:BL.READ := FBean.Invoke_Char('BL.BEAN_ITEM',1,'readFromFile','');
End if ;
The sample dialog
. Download the clientfile.zip file
. Unzip the file
. copy the clientfile.jar file in the <ORACLE_HOME>/forms/java directory
. Edit your /forms/server/formsweb.cfg file
. Open the CLIENTFILE.fmb module (Oracle Forms 10.1.2)
. Compile all and run the module