User`s manual

5 Calling Java from MATLAB
5-78
object FOS and a descriptive header string. It then calls close on the
FileOutputStream object, and returns.
case '6',
try
FOS = java.io.FileOutputStream(pbname);
catch
error(sprintf('Failed to open %s for writing.',...
pbname));
end;
pb_htable.save(FOS,'Data file for phonebook program');
FOS.close;
return;
otherwise
disp 'That selection is not on the menu.'
end;
end;
Description of Function pb_lookup
Arguments passed to pb_lookup are the Properties object pb_htable and the
name key for the requested entry. The pb_lookup function first calls get on
pb_htable with the name key, on which support function pb_keyfilter is
called to change spaces to underscores. The
get method returns the entry (or
null, if the entry is not found) to variable
entry. Note that get takes an
argument of type
java.lang.Object and also returns an argument of that
type. In this invocation, the key passed to
get and the entry returned from it
are actually character arrays.
pb_lookup then calls isempty to determine whether entry is null. If it is, it
uses
disp to display an message stating that the name was not found. If entry
is not
null, it calls pb_display to display the entry.
function pb_lookup(pb_htable,name)
entry = pb_htable.get(pb_keyfilter(name));
if isempty(entry),
disp(sprintf('The name %s is not in the phone book',name));
else
pb_display(entry);
end