Question: Course: Advanced Application Development 1. How do you create a Scanner object s that reads lines from the file in the src folder with file

Course: Advanced Application Development

1. How do you create a Scanner object s that reads lines from the file in the src folder with file name defined by names.txt?
String fileName = "names.txt"?

a. Scanner s = new Scanner(fileName);

b. Scanner s = new Scanner(new File("src/" + fileName));

c. Scanner s = Scanner.instanceOf(fileName);

d. Scanner s = Scanner.instanceOf(new File("src/" + fileName));

2. How do you create a PrintWriter object pw that writes lines to the file output.txt in the project folder?

a. PrintWriter pw = new PrintWriter(output.txt);

b. PrintWriter pw = new PrintWriter("output.txt");

c. PrintWriter pw = new PrintWriter(File("src/output.txt"));

d. PrintWriter pw = new PrintWriter(new Scanner("src/output.txt");

3. Which statement do you add to the method header when you are creating a new Scanner that reads from a file in that method?

a. catch FileNotFoundException

b. handles FileNotFoundException

c. new FileNotFoundException( )

d. throws FileNotFoundException

4. Which method is automatically called when an object is printed, for example, like this:
System.out.println(p);

a. The constructor for the class.

b. to_s

c. toString

d. __str__

5. Which Java statement is used to create an array of strings consisting of the fields in a comma delimited line?

a. String[ ] fields = line.split(",");

b. String[ ] fields = ",".split(line);

c. String[ ] fields = String.split(line, ",");

d. String[ ] fields = String.split(",", line);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Answer How do you create a Scanner object s that reads lines from the file in the src folder with fi... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!