Working with (Text) Files Flashcards

1
Q

When reading text files using the Scanner, and using a method other than nextLine(), what characters are used, by default, to separate tokens (tokens are each individual item that the scanner gets)?

A

Spaces (e.g. “ “)

New lines (e.g. “\n” )

Carriage return (e.g. “\r” )

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

True or False?
A programmer may specify a specific character that should be used to separate tokens in a text file being read by the scanner.

A

True

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

If a user were to delete a file that the Scanner was to use, then an error would occur. What is the formal name for an error of this kind?

A

Exception

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

If a piece of code, intended to read a file from disk using a Scanner, is not placed in a try-catch block, what would happen if it could not read the file due to it having been moved by the user?

A

The programme will crash

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

What single import statement could be used instead of the ones shown here:

import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;

A

import java.nio.file.*

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

The default behavior of Files.write() is to …

Hint, Caused an issue on assignment 2!

A

Overwrite any existing file with the same name.

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