题目内容

Given the following statement, which statement will write "Calvin" to the file DiskFile.txt?给定以下语句,哪个语句将“Calvin”写入文件DiskFile.txt?PrintWriter diskOut = new PrintWriter("DiskFile.txt");

A. System.out.println(diskOut, "Calvin");
B. DiskFile.println("Calvin");
C. PrintWriter.println("Calvin");
D. diskOut.println("Calvin");

查看答案
更多问题

When using the PrintWriter class, which of the following import statements would you write near the top of your program?使用PrintWriter类时,你需要在程序顶部附近写以下哪些语句?

A. import javax.swing.*;
B. import java.io.*;
C. import PrintWriter;
D. import java.file.*;

Which of the following will open a file named MyFile.txt and allow you to append data to its existing contents?下列哪一个可以打开一个名为MyFile.txt的文件,并可以将数据追加到其现有内容中?

A. FileWriter fwriter = new FileWriter("MyFile.txt", true);PrintWriter outFile = new PrintWriter(fwriter);
B. FileWriter fwriter = new FileWriter("MyFile.txt");PrintWriter outFile = new PrintWriter(fwriter);
C. PrintWriter outfile = new PrintWriter("MyFile.txt", true);
D. PrintWriter outfile = new PrintWriter(true, "MyFile.txt");

Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops shows the correct way to read data from t he file until the end of the file is reached?假设inputFile引用了Scanner对象。下列哪一项while循环显示了从文件读取数据直到到达文件结尾的正确方法?

A. while (inputFile != null){ … }
B. while (!inputFile.EOF){ … }
C. while (inputFile.hasNext()){ … }
D. while (inputFile.nextLine == " "){ … }

A constructor is a method that:构造函数是哪样一种方法。

A. returns an object of the class. 返回类的一个对象
B. never receives any arguments. 从来没有收到任何参数
C. with the name ClassName.constructor. ClassName.constructor名称
D. performs initialization or setup operations. 执行初始化或设置操作

答案查题题库