JAVA IO Flashcards
Some key points on the File System
- A file is a record within the file system that stores data.
- Files are organized into directories.
- Directory is a record in the file system that contains files as well as dircetories
What is a Path
String representation of a file/directory within the file system
What is the package of a File Class?
java.io.File
What is the File class used for?
- Read information about existing files and directories
- list the content of a directory
- create/delete files and directories
What does the instance of the File class represents?
Path name of a particular file/directory
What can a File class cannot do? * very important
Cannot read/write data within the File system.
Can a File class used to represent directories?
Yes
What is a relative path and what is absolute path?
- Relative path is the path from the current working directory to file or directory
- Absolute Path is the path of file/directory from root directory
Which slashdoes Unix and windows use
Unix: /
Windows: \
What are the two options to retrieve the local seperator character?
- System property
System.getProperty(“file.separator”); - Static variable
java.io.File.separator
Method to find whether the file exists or not?
file.exists()
What are the two constructors generally used for creating a file Instance
- One is taking String as argument representing relative/absolute path
- two arguments, one which is existing file path and other relative child path.
File file = new File(“C:\Dilli.txt”);
File file2 = new File(file, “hello\Dilli.txt”);
What is getName() does?
getName returns the name of the directory / file denoted by this path
What is getAbsolutePath()?
returns the absolute pathname String of the file/directory
lastModified()
returns the no of milliseconds since the epoch when the file was last modified
delete()
deletes the file/directory
If the pathname denotes a directory, then the directory must be empty in order to be deleted
mkdirs()
creates the directory named by this paths including any non-existent parent directories
listFiles()
returns the File[] Array returning the files on the directory
How can the contents of the file accessed/written?
Streams, which is a list of data elements presented sequentially
How to conceptually remember a Stream?
Think Stream as a long, never ending Stream of water with data presented one “wave” at a time
What are the three input streams java provides?
System.in, System.err, System.out
Difference b/w Streams and Reader/Writer classes?
- Stream classes are used for inputting and outputting all types of binary or byte data
- Reader/Writer classes are used for inputting and outputting only character and String data
Are Readers/Writers are streams?
Yes, even though their names doesnt contain Streams in it, they are streams