Input Output

Cards (77)

  • Volatile storage
    Temporary. Volatile values (stored in variables) are lost when the computer loses its power.
  • Non-volatile storage
    Permanent. A Java program that is saved on a disk uses a non-volatile storage.
  • Computer file
    A collection of data stored on a non-volatile device.
  • Text file
    Consists of data that can be read in a text editor. Data in a text file is encoded using a scheme, such as ASCII and Unicode. Examples are program files and application files.
  • Binary file
    Contains data that is not encoded as text. This file has contents in binary format, which means they cannot be understood by viewing them in a text editor.
  • Main directory/root directory
    Permanent files are stored here.
  • Folders/directories
    Organized stored files.
  • Path
    The complete list of the disk drive plus the hierarchy of directories in which the file is located.
  • Path delimiter
    The backslash (\) used to separate path components.
  • Path class
    Creates objects that contain information about files and directories, such as sizes, locations, creation dates, and is used to check whether a file or directory exists.
  • Files class
    Performs operations on files and directories, such as determining their attributes, creating input and output streams, and deleting them.
  • import java.nio.file.*;
    Use both the Path and Files classes.
  • Path filePath = Paths.get("C:\\Java\\Chapter8\\sample.txt
  • Absolute path
    A complete path; it does not require any other information to locate a file on a system.
  • Relative path
    Depends on other path information.
  • String toString()
    Returns the String representation of the Path, eliminating double Backslashes.
  • Path methods
    • getFileName(), getNameCount(), getName(int)
  • Path getFileName()
    Returns the file or directory denoted by this Path; this is the last item in the sequence of name elements.
  • int getNameCount()
    Returns the number of name elements in the Path.
  • Path getName(int)

    Returns the name in the position of the Path specified by the integer parameter.
  • toAbsolutePath()
    Convert a relative path to an absolute path.
  • checkAccess()
    Verify if a file exists and if a program can access it when needed.
  • delete()
    Method of the Files class accepts a Path parameter and removes the last element (file or directory) in a path or throws an exception if the deletion is unsuccessful.
  • Exceptionsthrownbydelete()

    • NoSuchFileException
    • DirectoryNotEmptyException
    • SecurityException
    • IOException
  • deleteIfExists()
    Method can also be used to remove a file without encountering an exception if the file does not exist.
  • readAttributes()
    To retrieve useful information about a file.
  • BasicFileAttributes.class
    The readAttributes() method returns an instance.
  • BasicFileAttributes methods
    • size(), creationTime(), lastModifiedTime(), compareTo()
  • size()

    Returns the size of the file in bytes.
  • creationTime()

    Returns the date and time the file was created.
  • lastModifiedTime()
    Returns the date and time the file was last edited.
  • compareTo()
    Compares relationship between values retrieved from creationTime() or lastModifiedTime().
  • Character
    The smallest useful piece of data and can be any letter, number, or other special symbol (such as punctuation mark) that makes up data.
  • Field
    A group of characters that has some meaning. Fields are grouped together to form records.
  • Record
    A collection of fields that contain data about an entity. Records are grouped to create files.
  • File
    Consists of related records.
  • Sequential access file
    Each record in a file is accessed one after another in the order in which it was stored, the data file is.
  • Comma-separated values

    A record's fields can be organized into a single line or can be separated by a character. Values in a record that are separated by commas.
  • Stream
    A flow of data.
  • Input stream
    The data is taken from a source (such as a file or the keyboard) and is delivered into a program.