File Input and Output
Quiz yourself by thinking what should be in
each of the black spaces below before clicking
on it to display the answer.
Help!
|
|
||||
---|---|---|---|---|---|
show | Is temporary; are lost when a computer loses power. Most computer professionals call volatile storage memory
🗑
|
||||
show | The temporary storage within a computer
🗑
|
||||
Nonvolatile Storage | show 🗑
|
||||
show | A collection of data stored on a nonvolatile device. Files exist on permanent storage devices, such as hard disks, Zip disks, USB drives, reels or cassettes or magnetic tape, and compact disks
🗑
|
||||
Text Files | show 🗑
|
||||
Data Files | show 🗑
|
||||
Program or Application Files | show 🗑
|
||||
Binary Files | show 🗑
|
||||
show | When you store a permanent file, you can place it in the main or root directory or your storage device
🗑
|
||||
Path | show 🗑
|
||||
show | The backslash character(\) in the Windows operating system used to separate path components
🗑
|
||||
Path Class | show 🗑
|
||||
show | Can be used to perform operations on files and directories, such as deleting them, determining their attributes, and creating input and output streams
🗑
|
||||
show | You can include the following statement in a Java program to use both the Path and Files classes...
input java.nio.file.*;...The nio in java.nio stands for new input/output.
🗑
|
||||
show | First determine the default file system on the host computer by using a statement such as follows...
FileSystem fs = FileSystems.getDefault();...This statement creates a FileSystem object using getDefault() method in FileSystems class.
🗑
|
||||
show | After you create a FileSystem object, you can define a Path using the getPath() method with it...
Path path = fs.getPath("C:\\Java\\Chapter.13\\Data.txt");.
🗑
|
||||
show | FileSystems, with an ending s, is a class that contains factory methods, which assist in object creation
🗑
|
||||
1. Alternative Way to Create a Path | show 🗑
|
||||
show | After the Path is created, you use its identifier(in this case, filePath) to refer to the file and perform operations on it
🗑
|
||||
Absolute Path | show 🗑
|
||||
show | Depends on other path information. Ex: SampleFile.txt
🗑
|
||||
1. Selected Path Class Methods | show 🗑
|
||||
2. Selected Path Class Methods | show 🗑
|
||||
3. Selected Path Class Methods | show 🗑
|
||||
toAbsolutePath() Method | show 🗑
|
||||
1. checkAccess() Method | show 🗑
|
||||
2. checkAccess() Method | show 🗑
|
||||
show | 1. No argument - Checks that the file exists; you can substitute the Files.exists() method and pass it a Path argument...
2. READ - Checks that the file exist as and that the program has permission to read the file...
🗑
|
||||
2. Arguments to the checkAccess() Method | show 🗑
|
||||
1. Deleting a Path | show 🗑
|
||||
2. Deleting a Path | show 🗑
|
||||
show | 3. If you try to delete a file but you don't have permission, a SecurityException is thrown...
4. Other input/output errors cause an IOException
🗑
|
||||
show | Can be used to delete a file, but if the file does not exist, no exception is thrown
🗑
|
||||
1. readAttributes() Method | show 🗑
|
||||
2. readAttributes() Method | show 🗑
|
||||
show | The size() method returns the size of a file in bytes. Methods creationTime() and lastModifiedTime() return important file times
🗑
|
||||
show | FileTime objects are represented in the following format: yyy-mm-ddThh:mm:ss...The four-digit year is followed by the two-digit month and two-digit day. Following a T for Time, the hour, minute, and seconds are separated by colons
🗑
|
||||
show | Used to determine the time relationship between files. Returns a value less than 0 if first FileTime comes before the argument's FileTime and greater than 0 if first FileTime is later than argument's FileTime.
🗑
|
||||
show | It returns 0 if the FileTime values are the same
🗑
|
||||
Character | show 🗑
|
||||
show | A group of characters that has some meaning. Ex: The characters T, o, and m might represent you first name(Tom). Characters are grouped together into fields
🗑
|
||||
Record | show 🗑
|
||||
show | Data files consist or related records, such as a company's personnel file that contains one record for each company employee. Records are grouped to create files
🗑
|
||||
Sequential Access File | show 🗑
|
||||
show | A file in which each value in a record is separated from the next by a comma; CSV is a widely used format for files used in all sorts of applications, including databases and spreadsheets
🗑
|
||||
show | You must open a file before the application can use it. A Java application opens a file by creating an object and associated a stream of bytes with it
🗑
|
||||
Closing a File | show 🗑
|
||||
show | A stream is an object, and like all object, streams have data and methods. The methods allows you to perform actions such as opening, closing, reading, and writing.
🗑
|
||||
2. Stream | show 🗑
|
||||
show | A memory location where bytes are held after they are logically output but before they are sent to the output device. Using a buffer to accumulate input or output before issuing the actual IO command improves program performance
🗑
|
||||
Flushing | show 🗑
|
||||
1. Classes Used for Input and Output | show 🗑
|
||||
show | 3. Class[BufferedInputStream]..Description[Child of FIlterInputStream, which is a child of InputStream; BufferedInputStream handles input from a system's standard input device, usually the keyboard]...
🗑
|
||||
3. Classes Used for Input and Output | show 🗑
|
||||
4. Classes Used for Input and Output | show 🗑
|
||||
5. Classes Used for Input and Output | show 🗑
|
||||
show | 8. Class[Reader]..Description[Abstract class for reading character streams; the only methods that a subclass must implement are rea(char[], int, int) and close()]...
🗑
|
||||
show | 9. Class[BufferedReader]..Description[Reads text from a character-input stream, buffering characters t provide for efficient reading of characters, arrays, and lines]...
🗑
|
||||
show | 10. Class[BufferedWriter]..Description[Writes text to a character-output stream, buffering characters to provide for the efficient writing of characters, arrays, and lines]
🗑
|
||||
show | 1. Method[void close()]..Description[Closes the output stream and releases any system resources associated with the stream]...
🗑
|
||||
show | 2. Method[void flush()]..Description[Flushes the output stream, if any bytes are buffered, they will be written]...
3. Method[void write(byte[] b)]..Description[Writes all the bytes to the output stream from the specified byte array]....
🗑
|
||||
show | 4. Method[void write(byte[] b, int off, int len)]..Description[Writes bytes to the output stream from the specified byte array starting at offset position off for a length of len characters]
🗑
|
||||
1. newOutputStream() Method | show 🗑
|
||||
show | Creates a file if it does not exist, opens for writing, and returns an OutputStream that can be used to write bytes to the file.
🗑
|
||||
1. StandardOpenOption Constants | show 🗑
|
||||
2. StandardOpenOption Constants | show 🗑
|
||||
3. StandardOpenOption Constants | show 🗑
|
||||
4. StandardOpenOption Constants | show 🗑
|
||||
show | To open a file for reading, you can use the Files class newInputStream() method. Accepts a Path parameter and return a stream that can read bytes from a file
🗑
|
||||
1. BufferedReader Methods | show 🗑
|
||||
2. BufferedReader Methods | show 🗑
|
||||
3. BufferedReader Methods | show 🗑
|
||||
show | 1. Method[close()]..Description[Closes the stream, flushing it first]...
2. Method[flush()]..Description[Flushes the stream]...
3. Method[newline()]..Description[Writes a line separator]...
🗑
|
||||
show | 4. Method[write(String s, int off, int len)]..Description[Writes a String from position off for length len]...
5. Method[write(char[], int off, int len)]..Description[Writes a character array from position off for length len]...
🗑
|
||||
3. BufferedWriter Method | show 🗑
|
||||
show | Accepts an arguments that identifies a field delimiter and returns an array of Strings in which each array element holds one field. Then you can use methods such as parseInt() and parseDouble() to convert the split strings to other data types
🗑
|
||||
show | Involves performing the same tasks with many records, one after the other
🗑
|
||||
show | For many applications, sequential access is inefficient. These applications, known as real-time applications, require that a record be accessed immediately while a client is waiting
🗑
|
||||
Interactive Program | show 🗑
|
||||
Random Access Files | show 🗑
|
||||
show | A file channel object is an avenue for reading and writing a file. You can use Java's FileChannel class to create your own random access files
🗑
|
||||
Seekable | show 🗑
|
||||
show | 1. Method[FileChannel open(Path file, OpenOption...options)]..Description[Opens or creates a file, returning a file channel to access the file]...
🗑
|
||||
2. FileChanel Methods | show 🗑
|
||||
show | 4. Method[int read(ByteBuffer buffer)]..Description[Reads a sequence of bytes from the channel into the buffer]...
5. Method[long size()]..Description[Returns the size of the channel's size]...
🗑
|
||||
4. FileChanel Methods | show 🗑
|
||||
ByteBuffer | show 🗑
|
||||
show | An array of bytes can be wrapped, or encompassed, into a ByteBuffer using this method. Wrapping a byte array into a buffer causes changed made to the buffer to change the array, and causes changes made to the array to change the buffer
🗑
|
||||
show | The field in a record that makes the record unique from all others
🗑
|
Review the information in the table. When you are ready to quiz yourself you can hide individual columns or the entire table. Then you can click on the empty cells to reveal the answer. Try to recall what will be displayed before clicking the empty cell.
To hide a column, click on the column name.
To hide the entire table, click on the "Hide All" button.
You may also shuffle the rows of the table by clicking on the "Shuffle" button.
Or sort by any of the columns using the down arrow next to any column heading.
If you know all the data on any row, you can temporarily remove it by tapping the trash can to the right of the row.
To hide a column, click on the column name.
To hide the entire table, click on the "Hide All" button.
You may also shuffle the rows of the table by clicking on the "Shuffle" button.
Or sort by any of the columns using the down arrow next to any column heading.
If you know all the data on any row, you can temporarily remove it by tapping the trash can to the right of the row.
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.
Normal Size Small Size show me how
Normal Size Small Size show me how
Created by:
TimJavaProgramming
Popular Engineering sets