IO streams Flashcards

(14 cards)

1
Q

What is Java I/O?

A

Java I/O (Input/Output) is a set of APIs that allows reading from and writing to data sources like files, network sockets, memory, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two main types of I/O streams in Java?

A

Byte streams (handles binary data) and character streams (handles text data).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between byte and character streams?

A

Byte streams (InputStream, OutputStream) process data as raw bytes; character streams (Reader, Writer) handle Unicode characters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which classes are used for reading from files using byte streams?

A

FileInputStream for reading and FileOutputStream for writing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which classes are used for reading and writing character data to files?

A

FileReader and FileWriter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of using Buffered streams?

A

To improve efficiency by reducing I/O operations.

Example: BufferedReader, BufferedWriter, BufferedInputStream, BufferedOutputStream.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the standard I/O in Java?

A

System.in (input), System.out (output), System.err (error stream).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the role of PrintWriter in Java I/O?

A

It’s used for writing formatted representations of objects to text-output streams, including to files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the try-with-resources statement?

A

A try block that automatically closes resources (like files) after execution. All classes must implement AutoCloseable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you read a line of text from a file using BufferedReader?

A

```java
BufferedReader reader = new BufferedReader(new FileReader(“file.txt”));
String line = reader.readLine();
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you write a string to a file using BufferedWriter?

A

```java
BufferedWriter writer = new BufferedWriter(new FileWriter(“file.txt”));
writer.write(“Hello, world!”);
writer.close();
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What exception must be handled or declared when using file I/O classes?

A

IOException.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the use of Scanner in file reading?

A

Scanner can read data from a file easily using methods like next(), nextLine(), nextInt(), etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why is closing streams important?

A

To release system resources and avoid memory leaks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly