ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/ifsraf.htm

97 lines
5.5 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="IFSRandomAccessFile" />
<meta name="abstract" content="The IFSRandomAccessFile class represents a file on the server for reading and writing data." />
<meta name="description" content="The IFSRandomAccessFile class represents a file on the server for reading and writing data." />
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="ifsraf" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>IFSRandomAccessFile</title>
</head>
<body id="ifsraf"><a name="ifsraf"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">IFSRandomAccessFile</h1>
<div><p>The IFSRandomAccessFile class represents a file on the server for
reading and writing data. </p>
<div class="section"><p><a href="javadoc/com/ibm/as400/access/IFSRandomAccessFile.html#NAVBAR_TOP"> IFSRandomAccessFile</a> </p>
<p>The Java™ program
can read and write data sequentially or randomly. As in IFSFile, methods exist
in IFSRandomAccessFile that duplicate the methods in RandomAccessFile from
the java.io package. In addition to these methods, IFSRandomAccessFile has
additional methods specific to the iSeries™ server. Through IFSRandomAccessFile,
a Java program
can do the following:</p>
<ul><li><a href="javadoc/com/ibm/as400/access/IFSRandomAccessFile.html#CONSTRUCTOR_DETAIL"> Open</a> a file for read, write, or read/write access. The Java program
can optionally specify the file sharing mode and the existence option.</li>
<li><a href="javadoc/com/ibm/as400/access/IFSRandomAccessFile.html#READ()"> Read</a> data at the current offset from the file.</li>
<li><a href="javadoc/com/ibm/as400/access/IFSRandomAccessFile.html#WRITE(INT)"> Write</a> data at the current offset to the file.</li>
<li><a href="javadoc/com/ibm/as400/access/IFSRandomAccessFile.html#GETFILEPOINTER()"> Get</a> or <a href="javadoc/com/ibm/as400/access/IFSRandomAccessFile.html#SEEK(LONG)"> set</a> the current offset of the file.</li>
<li><a href="javadoc/com/ibm/as400/access/IFSRandomAccessFile.html#CLOSE()"> Close</a> the file.</li>
</ul>
<p>In addition to the methods in java.io RandomAccessFile, IFSRandomAccessFile
gives the Java program the following options:</p>
<ul><li><a href="javadoc/com/ibm/as400/access/IFSRandomAccessFile.html#FLUSH()"> Committing</a> to disk bytes written.</li>
<li><a href="javadoc/com/ibm/as400/access/IFSRandomAccessFile.html#LOCK(INT, INT)"> Locking</a> or <a href="javadoc/com/ibm/as400/access/IFSRandomAccessFile.html#UNLOCK(COM.IBM.AS400.ACCESS.IFSKEY)"> unlocking</a> bytes in the file.</li>
<li>Locking and unlocking bytes in the stream. See <a href="ifskey.htm#ifskey">IFSKey</a> for
more information.</li>
<li>Specifying a sharing mode when the file is opened. See <a href="ifsmode.htm#ifsmode">sharing
modes</a> for more information.</li>
<li>Specify the existence option when a file is opened. The Java program
can choose one of the following: <ul><li>Open the file if it exists; create the file if it does not.</li>
<li>Replace the file if it exists; create the file if it does not.</li>
<li>Fail the open if the file exists; create the file if it does not.</li>
<li>Open the file if it exists; fail the open if it does not.</li>
<li>Replace the file if it exists; fail the open if it does not.</li>
</ul>
</li>
</ul>
</div>
<div class="section"><h4 class="sectiontitle">Example: Using IFSRandomAccessFile</h4><p>The following
example shows how to use the IFSRandomAccessFile class to write four bytes
at 1K intervals to a file.</p>
<pre> // Create an AS400 object.
AS400 sys = new AS400("mySystem.myCompany.com");
// Open a file object that represents
// the file.
IFSRandomAccessFile aFile = new IFSRandomAccessFile(sys,"/mydir1/myfile", "rw");
// Establish the data to write.
byte i = 123;
// Write to the file 10 times at 1K
// intervals.
for (int j=0; j&lt;10; j++)
{
// Move the current offset.
aFile.seek(j * 1024);
// Write to the file. The current
// offset advances by the size of
// the write.
aFile.write(i);
}
// Close the file.
aFile.close();</pre>
</div>
</div>
</body>
</html>