{"id":184,"date":"2021-01-19T22:17:22","date_gmt":"2021-01-19T22:17:22","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/?page_id=184"},"modified":"2021-01-19T22:28:31","modified_gmt":"2021-01-19T22:28:31","slug":"random-access-files","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/i-o-files-streams\/random-access-files\/","title":{"rendered":"Random Access Files"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a6d4ac9c4691\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a6d4ac9c4691\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/i-o-files-streams\/random-access-files\/#Class_RandomAccessFile\" >Class RandomAccessFile<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/i-o-files-streams\/random-access-files\/#Example\" >Example<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/i-o-files-streams\/random-access-files\/#Employee\" >Employee<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/i-o-files-streams\/random-access-files\/#EmployeeDataLoader\" >EmployeeDataLoader<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/i-o-files-streams\/random-access-files\/#EmployeeDataReader\" >EmployeeDataReader<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/course-topics\/i-o-files-streams\/random-access-files\/#EmployeeTree\" >EmployeeTree<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n<p class=\"wp-block-paragraph\">Here&#8217;s the class hierarchy to support random access files:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(Package&nbsp;<code><strong>java.io<\/strong><\/code>)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Object<strong>\n    RandomAccessFile<\/strong> (implements DataInput, DataOutput)<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>DataInput\n    ObjectInput<\/strong><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>DataOutput\n    ObjectOutput<\/strong><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Class_RandomAccessFile\"><\/span>Class RandomAccessFile<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Instances of class&nbsp;<code><strong>RandomAccessFile<\/strong><\/code>&nbsp;support both reading and writing to a random access file. A random access file behaves like a large array of bytes stored in the file system. There is a kind of cursor, or index into the implied array, called the&nbsp;<em>file pointer<\/em>; input operations read bytes starting at the file pointer and advance the file pointer past the bytes read. If the random access file is created in read\/write mode, then output operations are also available; output operations write bytes starting at the file pointer and advance the file pointer past the bytes written. Output operations that write past the current end of the implied array cause the array to be extended. The file pointer can be read by the <code><strong>getFilePointer<\/strong><\/code> method and set by the <code><strong>seek<\/strong><\/code> method.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is generally true of all the reading routines in this class that if end-of-file is reached before the desired number of bytes has been read, an&nbsp;<code><strong>EOFException<\/strong><\/code>&nbsp;is thrown. If any byte cannot be read for any reason other than end-of-file, an&nbsp;<code><strong>IOException<\/strong><\/code>&nbsp;other than&nbsp;<code><strong>EOFException<\/strong><\/code>&nbsp;is thrown. In particular, an&nbsp;<code><strong>IOException<\/strong><\/code>&nbsp;may be thrown if the stream has been closed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>RandomAccessFile<\/strong><\/code>&nbsp;has two constructors:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Constructor<\/th><th>Description<\/th><\/tr><tr><td><code>public <strong>RandomAccessFile<\/strong>(File&nbsp;file, String&nbsp;mode) throws IOException<\/code><\/td><td>Creates a random access file stream to read from, and optionally to write to, the file specified by the&nbsp;<code>File<\/code>&nbsp;argument.<\/td><\/tr><tr><td><code>public <strong>RandomAccessFile<\/strong>(String&nbsp;name, String&nbsp;mode) throws FileNotFoundException<\/code><\/td><td>Creates a random access file stream to read from, and optionally to write to, a file with the specified name.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">It implements the&nbsp;<strong>DataInput<\/strong>&nbsp;and&nbsp;<strong>DataOutput<\/strong>&nbsp;interfaces, and so it supports all the methods required by them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In addition, it implements the following methods:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Method<\/th><th>Description<\/th><\/tr><tr><td><code>public void <strong>close<\/strong>() throws IOException<\/code><\/td><td>Closes this random access file stream and releases any system resources associated with the stream. A closed random access file cannot perform input or output operations and cannot be reopened.<\/td><\/tr><tr><td><code>public final FileDescriptor <strong>getFD<\/strong>() throws IOException<\/code><\/td><td>Returns the opaque file descriptor object associated with this stream.<\/td><\/tr><tr><td><code>public long <strong>getFilePointer<\/strong>() throws IOException<\/code><\/td><td>Returns the current offset in this file.<\/td><\/tr><tr><td><code>public long <strong>length<\/strong>() throws IOException<\/code><\/td><td>Returns the length of this file.<\/td><\/tr><tr><td><code>public void <strong>seek<\/strong>(long&nbsp;pos) throws IOException<\/code><\/td><td>Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs. The offset may be set beyond the end of the file. Setting the offset beyond the end of the file does not change the file length. The file length will change only by writing after the offset has been set beyond the end of the file.<\/td><\/tr><tr><td><code>public void <strong>setLength<\/strong>(long&nbsp;newLength) throws IOException<\/code><\/td><td>Sets the length of this file.If the present length of the file as returned by the&nbsp;<code>length<\/code>&nbsp;method is greater than the&nbsp;<code>newLength<\/code>&nbsp;argument then the file will be truncated. In this case, if the file offset as returned by the&nbsp;<code>getFilePointer<\/code>&nbsp;method is greater then&nbsp;<code>newLength<\/code>&nbsp;then after this method returns the offset will be equal to&nbsp;<code>newLength<\/code>.If the present length of the file as returned by the&nbsp;<code>length<\/code>&nbsp;method is smaller than the&nbsp;<code>newLength<\/code>&nbsp;argument then the file will be extended. In this case, the contents of the extended portion of the file are not defined.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example\"><\/span>Example<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example of using the <strong>RandomAccessFile<\/strong> class.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Employee\"><\/span>Employee<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">First, let&#8217;s create a class that represents an employee, whose data we&#8217;ll be saving in a random access file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage randomAccess;\n\nimport java.io.IOException;\nimport java.io.PrintStream;\nimport java.io.PrintWriter;\nimport java.io.RandomAccessFile;\n\n\/**\n*   Class to represent an employee.\n*\n*   @author Bryan J. Higgs, 31 January, 2001\n*\/\npublic class Employee\n{\n    public static final int RECORD_SIZE = 4     \/\/ for the employeeNo\n                                        + 80    \/\/ for the name (40 characters)\n                                        + 8     \/\/ for the salary\n                                        + 4;    \/\/ for the managedBy\n\n    public static final int NO_MANAGER = -1;    \/\/ Means no managedBy\n\n    \/**\n    *   Constructor (used for constructing an object and\n    *   populating it using the read method),\n    *\/\n    public Employee()\n    {\n    }\n\n    \/**\n    *   Constructor.\n    *\/\n    public Employee(int employeeID, String name, double salary, int managedBy)\n    {\n        m_employeeID = employeeID;\n        m_name = name;\n        m_salary = salary;\n        m_managedBy = managedBy;\n    }\n\n    \/**\n    *   Returns the employee&#039;s ID.\n    *\/\n    public int getID()\n    {\n        return m_employeeID;\n    }\n\n    \/**\n    *   Returns the employee&#039;s name.\n    *\/\n    public String getName()\n    {\n        return m_name;\n    }\n\n    \/**\n    *   Returns the employee&#039;s salary.\n    *\/\n    public double getSalary()\n    {\n        return m_salary;\n    }\n\n    \/**\n    *   Returns the employee&#039;s manager&#039;s ID.\n    *\/\n    public int getManagedBy()\n    {\n        return m_managedBy;\n    }\n\n    \/**\n    *   Prints out the employee&#039;s information.\n    *\/\n    public void print()\n    {\n        PrintStream out = System.out;\n        out.println(&quot;Employee ID: &quot; + m_employeeID);\n        out.println(&quot;       Name: &quot; + m_name);\n        out.println(&quot;     Salary: $&quot; + m_salary);\n        out.println(&quot; Managed by: &quot; + m_managedBy);\n    }\n\n    \/**\n    *   Writes employee data to the specified file.\n    *\/\n    public void write(RandomAccessFile file)\n        throws IOException\n    {\n        file.writeInt(m_employeeID);\n        writeName(file);\n        file.writeDouble(m_salary);\n        file.writeInt(m_managedBy);\n    }\n\n    \/**\n    *   Reads employee data from the specified file.\n    *\/\n    public void read(RandomAccessFile file)\n        throws IOException\n    {\n        m_employeeID = file.readInt();\n        m_name = readName(file);\n        m_salary = file.readDouble();\n        m_managedBy = file.readInt();\n    }\n\n    \/\/\/\/ Private methods \/\/\/\/\n\n    \/**\n    *   Writes the employee&#039;s name to the specified file.\n    *   The name is truncated or padded to MAX_NAME_SIZE characters.\n    *\/\n    private void writeName(RandomAccessFile file)\n        throws IOException\n    {\n        StringBuffer buf = new StringBuffer(m_name);\n        buf.setLength(MAX_NAME_SIZE);   \/\/ Truncate or pad, as necessary\n        file.writeChars(buf.toString());\n    }\n\n    \/**\n    *   Reads the employee&#039;s name from the specified file.\n    *   The name is extracted, any padding removed, and then trimmed down.\n    *\/\n    private String readName(RandomAccessFile file)\n        throws IOException\n    {\n        StringBuffer buf = new StringBuffer();\n        for (int i = 0; i &lt; MAX_NAME_SIZE; i++)\n        {\n            buf.append( file.readChar() );\n        }\n        String name = buf.toString().replace(&#039;\\0&#039;, &#039; &#039;).trim();\n        return name;\n    }\n\n    \/\/\/\/\/\/ Private data \/\/\/\/\/\/\/\n    private static final int MAX_NAME_SIZE = 40;    \/\/ Characters\n\n    private int     m_employeeID = -1;   \/\/ Employee id\n    private String  m_name = &quot;&quot;;         \/\/ Employee name\n    private double  m_salary = 0.0;      \/\/ Employee salary\n    private int     m_managedBy = -1;    \/\/ Manager&#039;s employee id (-1 if no manager)\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"EmployeeDataLoader\"><\/span>EmployeeDataLoader<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">And here&#8217;s a class that loads employee data into a random access file:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage randomAccess;\n\nimport java.io.IOException;\nimport java.io.RandomAccessFile;\n\n\/**\n*   Class to load a set of employee data to a file.\n*\n*   @author Bryan J. Higgs, 31 January, 2001.\n*\/\npublic class EmployeeDataLoader\n{\n    \/**\n    *   Main entry point.\n    *\n    *   @param args command line arguments.\n    *               args&#x5B;0] is the name of the file to load.\n    *\/\n    public static void main(String&#x5B;] args)\n    {\n        if (args.length &lt; 1)\n        {\n            System.err.println(\n                &quot;Usage: java randomAccess.EmployeeDataLoader &lt;file-to-load&gt;&quot;);\n            return;\n        }\n        \/\/ Extract the filename\n        String fileName = args&#x5B;0];\n\n        \/\/ Construct all employees (empID, empName, empSalary, managedBy)\n        Employee bigBoss = new Employee(1, &quot;Richie Rich&quot;, 2000000.0, -1);\n        Employee cfo     = new Employee(2, &quot;Guy Noire&quot;, 200000.0, 1);\n        Employee hrBoss  = new Employee(3, &quot;Prescott Hireling&quot;, 100000.0, 1);\n        Employee sectry  = new Employee(4, &quot;Dottie Magnusson&quot;, 40000.0, 3);\n        Employee opsBoss = new Employee(5, &quot;Frank Getitdone&quot;, 120000.0, 1);\n        Employee minion  = new Employee(6, &quot;Joe Duzit&quot;, 30000.0, 5);\n\n        RandomAccessFile file = null;\n        try\n        {\n            \/\/ Create random access file object for writing.\n            file = new RandomAccessFile(fileName, &quot;rw&quot;);\n            \/\/ Write all employees to the file\n            \/\/ NOTE: The employee ID is the index of the employee data,\n            \/\/       so the employees are written in employee ID order.\n            bigBoss.write(file);\n            cfo.write(file);\n            hrBoss.write(file);\n            sectry.write(file);\n            opsBoss.write(file);\n            minion.write(file);\n        }\n        catch (IOException ex)\n        {\n            ex.printStackTrace();\n        }\n        finally\n        {\n            \/\/ Close the file, under all circumstances.\n            if (file != null)\n            {\n                try\n                {\n                    file.close();\n                }\n                catch (IOException ex)\n                {\n                    \/\/ Ignore\n                }\n            }\n        }\n    }\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"EmployeeDataReader\"><\/span>EmployeeDataReader<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Now, here&#8217;s a class that reads the data back in from the file, reading employees sequentially:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage randomAccess;\n\nimport java.io.EOFException;\nimport java.io.IOException;\nimport java.io.RandomAccessFile;\n\n\/**\n*   Class to read a set of employee data from a file.\n*\n*   @author Bryan J. Higgs, 31 January, 2001.\n*\/\npublic class EmployeeDataReader\n{\n    \/**\n    *   Main entry point.\n    *\n    *   @param args command line arguments.\n    *               args&#x5B;0] is the name of the file to read.\n    *\/\n    public static void main(String&#x5B;] args)\n    {\n        if (args.length &lt; 1)\n        {\n            System.err.println(\n                &quot;Usage: java randomAccess.EmployeeDataReader &lt;file-to-read&gt;&quot;);\n            return;\n        }\n        \/\/ Extract the filename\n        String fileName = args&#x5B;0];\n\n        RandomAccessFile file = null;\n        try\n        {\n            \/\/ Create random access file object for reading\n            file = new RandomAccessFile(fileName, &quot;r&quot;);\n\n            \/\/ Read the employees, in sequential order.\n            while (true)\n            {\n                Employee emp = new Employee();\n                emp.read(file);\n                emp.print();\n            }\n        }\n        catch (EOFException ex)\n        {\n            \/\/ Do nothing;  there are no more records to read\n        }\n        catch (IOException ex)\n        {\n            ex.printStackTrace();\n        }\n        finally\n        {\n            \/\/ Close file, under all circumstances.\n            if (file != null)\n            {\n                try\n                {\n                    file.close();\n                }\n                catch (IOException ex)\n                {\n                    \/\/ Ignore\n                }\n            }\n        }\n    }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">which produces the following output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Employee ID: 1\n       Name: Richie Rich\n     Salary: $2000000.0\n Managed by: -1\nEmployee ID: 2\n       Name: Guy Noire\n     Salary: $200000.0\n Managed by: 1\nEmployee ID: 3\n       Name: Prescott Hireling\n     Salary: $100000.0\n Managed by: 1\nEmployee ID: 4\n       Name: Dottie Magnusson\n     Salary: $40000.0\n Managed by: 3\nEmployee ID: 5\n       Name: Frank Getitdone\n     Salary: $120000.0\n Managed by: 1\nEmployee ID: 6\n       Name: Joe Duzit\n     Salary: $30000.0\n Managed by: 5<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"EmployeeTree\"><\/span>EmployeeTree<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, here&#8217;s how we can do random access to the file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We now read the file using random access, to build a simple &#8216;org chart&#8217; of the employees:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\npackage randomAccess;\n\nimport java.io.EOFException;\nimport java.io.IOException;\nimport java.io.RandomAccessFile;\n\n\/**\n*   Class to print out a management hierarchy, given an employee ID.\n*\n*   @author Bryan J. Higgs, 31 January, 2001.\n*\/\npublic class EmployeeTree\n{\n    \/**\n    *   Main entry point.\n    *\n    *   @param args command line arguments.\n    *               args&#x5B;0] is the name of the file to read.\n    *               args&#x5B;1] is the employee ID.\n    *\/\n    public static void main(String&#x5B;] args)\n    {\n        if (args.length &lt; 2)\n        {\n            System.err.println(\n                &quot;Usage: java randomAccess.EmployeeTree &lt;file-to-read&gt; &lt;empID&gt;&quot;);\n            return;\n        }\n        \/\/ Extract the filename\n        String fileName = args&#x5B;0];\n        \/\/ Extract the employee ID\n        int empID = Integer.parseInt(args&#x5B;1]);\n\n        RandomAccessFile file = null;\n        try\n        {\n            \/\/ Create random access file object for reading\n            file = new RandomAccessFile(fileName, &quot;r&quot;);\n            \/\/ Print the management hierarchy\n            printTree(file, empID);\n            \/\/ end it with a fresh newline\n            System.out.println();\n        }\n        catch (IOException ex)\n        {\n            ex.printStackTrace();\n        }\n        finally\n        {\n            if (file != null)\n            {\n                try\n                {\n                    file.close();\n                }\n                catch (IOException ex)\n                {\n                    \/\/ Ignore\n                }\n            }\n        }\n    }\n\n    \/**\n    *   Prints out a management hierarchy, given an employee ID\n    *\/\n    private static int printTree(RandomAccessFile file, int empID)\n        throws IOException\n    {\n        \/\/ Calculate position of employee record in file.\n        long position = (empID-1) * Employee.RECORD_SIZE;\n        \/\/ Seek to it.\n        file.seek(position);\n        \/\/ Read employee data\n        Employee emp = new Employee();\n        emp.read(file);\n        \/\/ Perform a sanity check\n        if (emp.getID() != empID)\n        {\n            throw new IllegalStateException(\n                            &quot;Employee IDs don&#039;t match:&quot; + empID + &quot;, &quot; + emp.getID());\n        }\n\n        int level = 0;  \/\/ Used for indentation\n        if (emp.getManagedBy() != Employee.NO_MANAGER)\n        {\n            \/\/ If employee has a manager, recurse\n            level = printTree(file, emp.getManagedBy());\n            \/\/ Indent to level\n            for (int i = 0; i &lt; level; i++)\n                System.out.print(&#039; &#039;);\n            System.out.print(&quot;manages &quot;);\n        }\n        \/\/ Print out employee name\n        System.out.println(emp.getName());\n\n        return ++level;\n    }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">which produces the following output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Richie Rich\n manages Frank Getitdone\n  manages Joe Duzit<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s the class hierarchy to support random access files: (Package&nbsp;java.io) Object RandomAccessFile (implements DataInput, DataOutput) DataInput ObjectInput DataOutput ObjectOutput Class RandomAccessFile Instances of class&nbsp;RandomAccessFile&nbsp;support both reading and writing to a random access file. A random access file behaves like a large array of bytes stored in the file system. There is a kind of cursor, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":67,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_eb_attr":"","ocean_front_end_style_editor":"no","ocean_post_layout":"left-sidebar","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"ocs-course-topics-sidebar","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","footnotes":""},"class_list":["post-184","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages\/184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/comments?post=184"}],"version-history":[{"count":5,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages\/184\/revisions"}],"predecessor-version":[{"id":193,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages\/184\/revisions\/193"}],"up":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/pages\/67"}],"wp:attachment":[{"href":"https:\/\/bhiggs.x10hosting.com\/HighOctaneJava\/wp-json\/wp\/v2\/media?parent=184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}