Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## java.io
Class File

    java.lang.Object
      java.io.File

    public class File

extends Object

Implements a file system using pages of flash memory. Currently has limited functionality and only supports one file open at a time.

Author:
  Brian Bagnall

Field Summary
`static byte` | `MAX_FILES` Number of files the file system can store.
`static byte` | `totalFiles` The total number of files in the file system.

Constructor Summary
`File(String name)` Creates a new File object.

Method Summary
`boolean` | `canRead()`
`boolean` | `canWrite()`
`boolean` | `createNewFile()` Creates a new file entry in the flash memory.
`static void` | `defrag()` Defrag the file system.
`boolean` | `delete()` Deletes the file represented by this File object.
`static void` | `dumpFileTable()` Debugger method.
`void` | `exec()` If the file is a binary executable, begins running it.
`boolean` | `exists()` Indicates if the file exists in the flash memory.
`static void` | `format()` Essentially formats the file system by writing TABLE_ID characters to the first page of flash memroy.
`static int` | `freeMemory()` Returns to total free memory in the flash file system.
`int` | `getIndex()` Returns location of file in the files[] array
`String` | `getName()` Returns the name of the file.
`int` | `getPage()` Internal method used to get the page number of the start of the file.
`boolean` | `isHidden()`
`int` | `length()` Returns the length of the file denoted by this file name.
`static File[]` | `listFiles()` Returns a list of files in the flash file system.
`void` | `moveToTop()` Move the file to become the last one in flash memory.
`static void` | `reset()` Reset the files array after an error.
`boolean` | `setReadOnly()`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait`

Field Detail

### MAX_FILES

    public static final byte MAX_FILES

  Number of files the file system can store. Defines the size of the files array. If leJOS gets a garbage collector we can get rid of this limitation.

  See Also:
    Constant Field Values

### totalFiles

    public static byte totalFiles

  The total number of files in the file system. A negative value indicates this variable has not been initialized. Using byte, but if we expand past the 30 limit (garbage collector) we can use short.

Constructor Detail

### File

    public File(String name)

  Creates a new File object. If this file exists on disk it will represent that file. If the file does not exist, you will need to use createNewFile() before writing to the file.

  Parameters:
    `name` -

Method Detail

### delete

    public boolean delete()

  Deletes the file represented by this File object.

  Returns:
    true if the file is successfully deleted; false otherwise

### exec

    public void exec()

  If the file is a binary executable, begins running it.

### listFiles

    public static File[] listFiles()

  Returns a list of files in the flash file system. Because there are no directories, this is a static method in leJOS NXJ. The order of the files in the array goes from oldest (0) to newest (highest index array).

  Returns:
    An array of File objects representing files in the file system. The array will be empty if the directory is empty. NOTE: In the Java SDK this method should return an array of size equaling the number of files. However, because leJOS has no garbage collector it returns the same array that is always 30 in length. The unused file spots are null. Use File.totalFiles to determine number of files.

### getName

    public String getName()

  Returns the name of the file.

  Returns:
    The name of the file, including the file extension. e.g. "mapdata.txt"

### length

    public int length()

  Returns the length of the file denoted by this file name.

  Returns:
    The length, in bytes, of the file denoted by this file name, or 0 if the file does not exist.

### exists

    public boolean exists()

  Indicates if the file exists in the flash memory.

  Returns:
    True indicates the file exists, false means it has not been created.

### canRead

    public boolean canRead()

### canWrite

    public boolean canWrite()

### isHidden

    public boolean isHidden()

### setReadOnly

    public boolean setReadOnly()

### dumpFileTable

    public static void dumpFileTable()

  Debugger method. Comment out when no longer buggy.

### format

    public static void format()

  Essentially formats the file system by writing TABLE_ID characters to the first page of flash memroy. Also writes 0 as the number of files in the file system, so it can be used to restart/erase all files.

### createNewFile

    public boolean createNewFile()
                          throws IOException

  Creates a new file entry in the flash memory.

  Returns:
    True indicates file was created in flash. False means it already existed or the size is 0 or less.
  Throws:
    `IOException`

### moveToTop

    public void moveToTop()
                   throws IOException

  Move the file to become the last one in flash memory.

  Throws:
    `IOException`

### freeMemory

    public static int freeMemory()

  Returns to total free memory in the flash file system.

### getIndex

    public int getIndex()

  Returns location of file in the files[] array

  Returns:
    index of file in files[]

### defrag

    public static void defrag()
                       throws IOException

  Defrag the file system. WARNING: should only be called from the startup menu. If called from a user program, can cause the current program to be moved resulting in a data abort of other firmware crash. Assumptions: the files[] array has no nulls, and is in increasing order by page_location. This scheme moves moves each file down to fill in the empty pages.

  Throws:
    `IOException`

### getPage

    public int getPage()

  Internal method used to get the page number of the start of the file.

  Returns:
    page number

### reset

    public static void reset()

  Reset the files array after an error. Forces listFiles to read from the file table.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD