JAVA IO Flashcards Preview

Java8 > JAVA IO > Flashcards

Flashcards in JAVA IO Deck (59)
Loading flashcards...
1

Some key points on the File System

1. A file is a record within the file system that stores data.
2. Files are organized into directories.
3. Directory is a record in the file system that contains files as well as dircetories

2

What is a Path

String representation of a file/directory within the file system

3

What is the package of a File Class?

java.io.File

4

What is the File class used for?

1. Read information about existing files and directories
2. list the content of a directory
3. create/delete files and directories

5

What does the instance of the File class represents?

Path name of a particular file/directory

6

What can a File class cannot do?
* very important

Cannot read/write data within the File system.

7

Can a File class used to represent directories?

Yes

8

What is a relative path and what is absolute path?

1. Relative path is the path from the current working directory to file or directory
2. Absolute Path is the path of file/directory from root directory

9

Which slashdoes Unix and windows use

Unix: /
Windows: \

10

What are the two options to retrieve the local seperator character?

1. System property
System.getProperty("file.separator");
2. Static variable
java.io.File.separator

11

Method to find whether the file exists or not?

file.exists()

12

What are the two constructors generally used for creating a file Instance

1. One is taking String as argument representing relative/absolute path
2. 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");

13

What is getName() does?

getName returns the name of the directory / file denoted by this path

14

What is getAbsolutePath()?

returns the absolute pathname String of the file/directory

15

lastModified()

returns the no of milliseconds since the epoch when the file was last modified

16

delete()

deletes the file/directory

If the pathname denotes a directory, then the directory must be empty in order to be deleted

17

mkdirs()

creates the directory named by this paths including any non-existent parent directories

18

listFiles()

returns the File[] Array returning the files on the directory

19

How can the contents of the file accessed/written?

Streams, which is a list of data elements presented sequentially

20

How to conceptually remember a Stream?

Think Stream as a long, never ending Stream of water with data presented one "wave" at a time

21

What are the three input streams java provides?

System.in, System.err, System.out

22

Difference b/w Streams and Reader/Writer classes?

1. Stream classes are used for inputting and outputting all types of binary or byte data
2. Reader/Writer classes are used for inputting and outputting only character and String data

23

Are Readers/Writers are streams?

Yes, even though their names doesnt contain Streams in it, they are streams

24

Why we use character Streams?

1. There are advantages of using reader/writer clsses as they are specifically focussed on managing character and string data
2. WE DONT WANT TO WORRY ABOUT THE UNDERLYING BYTE ENCODING OF THE FILE

25

How can we differentiate streams as levels?

Low-Level Stream and High-Level Streams.

26

What is Low-level Streams?

Low level Streams connects directly with the source of the data such as files, arrays or Strings.
They process the raw data or resources and are accessed in a direct or unfiltered manner.

27

What are high level Sreams?

High level Streams is built on anoter Stream using wrapping. (An instance is passed as constructor to another instance)

28

What are the four abstract classes that are parent for all streams?

1. InputStream
2. OutputStream
3. Reader
4. Writer

29

Which is the parent class of PrintStream?

OutputStream

30

new BufferedInputStream(new FileReader("C:\\hello.txt"));
new BufferedWriter(new FileOutputStream("C:\\hello.txt"));
new ObjectInputStream(new FileOutputStream("C:\\hello.txt"));
new BufferedInputStream(new InputStream("hello.txt"));

will these comile?

No. First two mix Reader/Writer classes with InputStream/OutputStream classes.

Third does not compile bcause it mixes with Input Stream with Output Steam

4th doesnt compile because, InputStream is a abstract class, no constructor is allowed