单选题The file “file.txt” exists on the file system and contsins ASCII text.  Given:   try {   File f = new File(“file.txt”);    OutputStream out = new FileOutputStream(f, true);   }    catch (IOException) {}   What is the result?()AThe code does not compile

题目
单选题
The file “file.txt” exists on the file system and contsins ASCII text.  Given:   try {   File f = new File(“file.txt”);    OutputStream out = new FileOutputStream(f, true);   }    catch (IOException) {}   What is the result?()
A

 The code does not compile.

B

 The code runs and no change is made to the file.

C

 The code runs and sets the length of the file to 0.

D

 An exception is thrown because the file is not closed.

E

 The code runs and deletes the file from the file system.


相似考题
更多“单选题The file “file.txt” exists on the file system and contsins ASCII text.  Given:   try {   File f = new File(“file.txt”);    OutputStream out = new FileOutputStream(f, true);   }    catch (IOException) {}   What is the result?()A  The code does not compi”相关问题
  • 第1题:

    Given that the current directory is empty, and that the user has read and write permissions, and the following:Which statement is true?()

    A.Compilation fails.

    B.The file system has a new empty directory named dir.

    C.The file system has a new empty directory named newDir.

    D.The file system has a directory named dir, containing a file f1.txt.

    E.The file system has a directory named newDir, containing a file f1.txt.


    参考答案:E

  • 第2题:

    创建一个向文件“file.txt”追加内容的输出流对象的语句有()。

    • A、FileOutputStream out=new FileOutputStream(“file.txt”,true);
    • B、OutputStream out=new FileOutputStream(“file.txt”,“append”);
    • C、OutputStream out=new FileOutputStream(“file.txt”);
    • D、FileOutputStream out=new FileOutputStream(new file(“file.txt”));
    • E、OutputStream out=new FileOutputStream(new File(“file.txt”),true.;

    正确答案:A,E

  • 第3题:

    Which statements are true, given the code new FileOutputStream("data", true) for creating an object of class FileOutputStream?()  

    • A、FileOutputStream has no constructors matching the given arguments.
    • B、An IOExeception will be thrown if a file named "data" already exists.
    • C、An IOExeception will be thrown if a file named "data" does not already exist.
    • D、If a file named "data" exists, its contents will be reset and overwritten.
    • E、If a file named "data" exists, output will be appended to its current contents.

    正确答案:E

  • 第4题:

    Which of the following will occur if an operator types the command vi file.out?()

    • A、If the file exists it will be opened for editing. If the file does not exist an error message will be displayed.
    • B、If the file exists it will be opened for editing. If the file does not exist a new file with the name file.out will be created and opened for editing.
    • C、If the file exists an error message will be displayed. If the file does not exist a new file with the name file.out will be created and opened for editing.
    • D、If the file exists the operator will be asked whether to open the file or overwrite the file. If the file does not exist a new file with the name file.out will be created and opened for editing.

    正确答案:B

  • 第5题:

    Which determines if “prefs” is a directory and exists on the file system?()  

    • A、 Boolean exists=Directory.exists (“prefs”);
    • B、 Boolean exists=(new File(“prefs”)).isDir();
    • C、 Boolean exists=(new Directory(“prefs”)).exists();
    • D、 Boolean exists=(new File(“prefs”)).isDirectory();
    • E、 Boolean exists=true;  Try{  Directory d = new Directory(“prefs”);  } catch (FileNotFoundException e) {  exists = false;  }

    正确答案:D

  • 第6题:

    The file “file.txt” exists on the file system and contsins ASCII text.  Given:   try {   File f = new File(“file.txt”);    OutputStream out = new FileOutputStream(f, true);   }    catch (IOException) {}   What is the result?()

    • A、 The code does not compile.
    • B、 The code runs and no change is made to the file.
    • C、 The code runs and sets the length of the file to 0.
    • D、 An exception is thrown because the file is not closed.
    • E、 The code runs and deletes the file from the file system.

    正确答案:A

  • 第7题:

    What writes the text “ ” to the end of the file “file.txt”?()

    • A、 OutputStream out= new FileOutputStream (“file.txt”);       Out.writeBytes (“ /n”);
    • B、 OutputStream os= new FileOutputStream (“file.txt”, true);       DataOutputStream out = new DataOutputStream(os);  out.writeBytes (“ /n”);
    • C、 OutputStream os= new FileOutputStream (“file.txt”);       DataOutputStream out = new DataOutputStream(os);  out.writeBytes (“ /n”);
    • D、 OutputStream os= new OutputStream (“file.txt”, true);     DataOutputStream out = new DataOutputStream(os);  out.writeBytes (“ /n”);

    正确答案:B

  • 第8题:

    单选题
    Which method implementations will write the given string to a file named "file", using UTF8 encoding?()   IMPLEMENTATION a:   public void write(String msg) throws IOException {   FileWriter fw = new FileWriter(new File("file"));   fw.write(msg);   fw.close();   }   IMPLEMENTATION b:   public void write(String msg) throws IOException {   OutputStreamWriter osw =  new OutputStreamWriter(new FileOutputStream("file"), "UTF8");  osw.write(msg);   osw.close();   }   IMPLEMENTATION c:   public void write(String msg) throws IOException {  FileWriter fw = new FileWriter(new File("file"));   fw.setEncoding("UTF8");   fw.write(msg);   fw.close();  }   IMPLEMENTATION d:   public void write(String msg) throws IOException {  FilterWriter fw = FilterWriter(new FileWriter("file"), "UTF8");   fw.write(msg);  fw.close();   }   IMPLEMENTATION e:   public void write(String msg) throws IOException {   OutputStreamWriter osw = new OutputStreamWriter(  new OutputStream(new File("file")), "UTF8"  );   osw.write(msg);   osw.close();   }
    A

    Implementation a.

    B

    Implementation b.

    C

    Implementation c.

    D

    Implementation d.

    E

    Implementation e.


    正确答案: D
    解析: 暂无解析

  • 第9题:

    单选题
    Which determines if “prefs” is a directory and exists on the file system?()
    A

     Boolean exists=Directory.exists (“prefs”);

    B

     Boolean exists=(new File(“prefs”)).isDir();

    C

     Boolean exists=(new Directory(“prefs”)).exists();

    D

     Boolean exists=(new File(“prefs”)).isDirectory();

    E

     Boolean exists=true;  Try{  Directory d = new Directory(“prefs”);  } catch (FileNotFoundException e) {  exists = false;  }


    正确答案: C
    解析: 暂无解析

  • 第10题:

    多选题
    创建一个向文件“file.txt”追加内容的输出流对象的语句有()。
    A

    FileOutputStream out=new FileOutputStream(“file.txt”,true);

    B

    OutputStream out=new FileOutputStream(“file.txt”,“append”);

    C

    OutputStream out=new FileOutputStream(“file.txt”);

    D

    FileOutputStream out=new FileOutputStream(new file(“file.txt”));

    E

    OutputStream out=new FileOutputStream(new File(“file.txt”),true.;


    正确答案: B,E
    解析: 暂无解析

  • 第11题:

    单选题
    Which statements are true, given the code new FileOutputStream("data", true) for creating an object of class FileOutputStream?()
    A

    FileOutputStream has no constructors matching the given arguments.

    B

    An IOExeception will be thrown if a file named data already exists.

    C

    An IOExeception will be thrown if a file named data does not already exist.

    D

    If a file named data exists, its contents will be reset and overwritten.

    E

    If a file named data exists, output will be appended to its current contents.


    正确答案: A
    解析: 暂无解析

  • 第12题:

    单选题
    The file “file.txt” exists on the file system and contsins ASCII text.  Given:   try {   File f = new File(“file.txt”);    OutputStream out = new FileOutputStream(f, true);   }    catch (IOException) {}   What is the result?()
    A

     The code does not compile.

    B

     The code runs and no change is made to the file.

    C

     The code runs and sets the length of the file to 0.

    D

     An exception is thrown because the file is not closed.

    E

     The code runs and deletes the file from the file system.


    正确答案: C
    解析: 暂无解析

  • 第13题:

    现有一个文件file21.txt,其内容是: abCdEf, 执行下列程序之后,输出的结果是______。 package ch1; import java,io.*; public class ex21 { static String name = "ch1\\file21.txt"; public static void main(String[] args) { try { readFile (); } catch(IOException ioe) { System.out.println(ioe.getMessage()); } } static void readFile () throws IOException { BufferedReader br = null; try { File f = new File(name); FileReader fr = new FileReader(f); br = new BufferedReader(fr); String str= br.readLine(); System.out.println(str.toLowerCase()); } finally if(br != null) br.close (); } } }

    A.AbCdEf

    B.abcdef

    C.aBcDeF

    D.ABCDEF


    正确答案:B

  • 第14题:

    Which two construct an OutputSream that appends to the file “file.txt”? ()

    • A、 OutputStream out=new FileOutputStream(“file.txt”);
    • B、 OutputStream out=new FileOutputStream(“file.txt”, “append”);
    • C、 FileOutputStream out=new FileOutputStream(“file.txt”, true);
    • D、 FileOutputStream out=new FileOutputStream(new file(“file.txt”));
    • E、 OutputStream out=new FileOutputStream(new File(“file.txt”)true);

    正确答案:C,E

  • 第15题:

    为文件c:/java/example/file.txt建立File对象file1可以采用()语句序列。

    • A、File file 1=new File(“c://java//example//file.txt”)
    • B、String path=”c:/java/example/”Filefile1=newFile(path,”oldfile.txt”)
    • C、File dir 1=new File(“c://java//example”)Filefile1=newFile(dir1,”oldfile.txt”)
    • D、File file 1=new File(“c:/java//example/file.txt”)

    正确答案:A,B,C

  • 第16题:

    Which two create an InputStream and open file the “file.txt” for reading? ()

    • A、 InputStream in=new FileReader(“file.txt”);
    • B、 InputStream in=new FileInputStream(“file.txt”);
    • C、 InputStream in=new InputStreamFileReader (“file.txt”, “read”);
    • D、 FileInputStream in=new FileReader(new File(“file.txt”));
    • E、 FileInputStream in=new FileInputStream(new File(“file.txt”));

    正确答案:B,E

  • 第17题:

    Which gets the name of the parent directory file “file.txt”?()

    • A、 String name= File.getParentName(“file.txt”);
    • B、 String name= (new File(“file.txt”)).getParent();
    • C、 String name = (new File(“file.txt”)).getParentName();
    • D、 String name= (new File(“file.txt”)).getParentFile();
    • E、 Directory dir=(new File (“file.txt”)).getParentDir();  String name= dir.getName();

    正确答案:B

  • 第18题:

    10. class MakeFile {  11. public static void main(String[] args) {  12. try {  13. File directory = new File(”d”);  14. File file = new File(directory,”f”);  15. if(!file.exists()) {  16. file.createNewFile();  17. }  18. } catch (IOException e) {  19. e.printStackTrace  20. }  21. }  22. }  The current directory does NOT contain a directory named “d.” Which three are true?()

    • A、 Line 16 is never executed.
    • B、 An exception is thrown at runtime.
    • C、 Line 13 creates a File object named “d”.
    • D、 Line 14 creates a File object named “f‟.
    • E、 Line 13 creates a directory named “d” in the file system.
    • F、 Line 16 creates a directory named “d” and a file  “f”  within it in the file system.
    • G、 Line 14 creates a file named "f " inside of the directory named “d” in the file system.

    正确答案:B,C,D

  • 第19题:

    单选题
    Which of the following will occur if an operator types the command vi file.out?()
    A

    If the file exists it will be opened for editing. If the file does not exist an error message will be displayed.

    B

    If the file exists it will be opened for editing. If the file does not exist a new file with the name file.out will be created and opened for editing.

    C

    If the file exists an error message will be displayed. If the file does not exist a new file with the name file.out will be created and opened for editing.

    D

    If the file exists the operator will be asked whether to open the file or overwrite the file. If the file does not exist a new file with the name file.out will be created and opened for editing.


    正确答案: B
    解析: 暂无解析

  • 第20题:

    多选题
    10. class MakeFile {  11. public static void main(String[] args) {  12. try {  13. File directory = new File(”d”);  14. File file = new File(directory,”f”);  15. if(!file.exists()) {  16. file.createNewFile();  17. }  18. } catch (IOException e) {  19. e.printStackTrace  20. }  21. }  22. }  The current directory does NOT contain a directory named “d.” Which three are true?()
    A

    Line 16 is never executed.

    B

    An exception is thrown at runtime.

    C

    Line 13 creates a File object named “d”.

    D

    Line 14 creates a File object named “f‟.

    E

    Line 13 creates a directory named “d” in the file system.

    F

    Line 16 creates a directory named “d” and a file  “f”  within it in the file system.

    G

    Line 14 creates a file named f inside of the directory named “d” in the file system.


    正确答案: E,D
    解析: 暂无解析

  • 第21题:

    单选题
    What writes the text “ ” to the end of the file “file.txt”?()
    A

     OutputStream out= new FileOutputStream (“file.txt”);       Out.writeBytes (“ /n”);

    B

     OutputStream os= new FileOutputStream (“file.txt”, true);       DataOutputStream out = new DataOutputStream(os);  out.writeBytes (“ /n”);

    C

     OutputStream os= new FileOutputStream (“file.txt”);       DataOutputStream out = new DataOutputStream(os);  out.writeBytes (“ /n”);

    D

     OutputStream os= new OutputStream (“file.txt”, true);     DataOutputStream out = new DataOutputStream(os);  out.writeBytes (“ /n”);


    正确答案: C
    解析: 暂无解析

  • 第22题:

    单选题
    Which gets the name of the parent directory file “file.txt”?()
    A

     String name= File.getParentName(“file.txt”);

    B

     String name= (new File(“file.txt”)).getParent();

    C

     String name = (new File(“file.txt”)).getParentName();

    D

     String name= (new File(“file.txt”)).getParentFile();

    E

     Directory dir=(new File (“file.txt”)).getParentDir();  String name= dir.getName();


    正确答案: A
    解析: 暂无解析

  • 第23题:

    多选题
    Which two construct an OutputSream that appends to the file “file.txt”? ()
    A

    OutputStream out=new FileOutputStream(“file.txt”);

    B

    OutputStream out=new FileOutputStream(“file.txt”, “append”);

    C

    FileOutputStream out=new FileOutputStream(“file.txt”, true);

    D

    FileOutputStream out=new FileOutputStream(new file(“file.txt”));

    E

    OutputStream out=new FileOutputStream(new File(“file.txt”)true);


    正确答案: C,E
    解析: 暂无解析

  • 第24题:

    多选题
    为文件c:/java/example/file.txt建立File对象file1可以采用()语句序列。
    A

    File file 1=new File(“c://java//example//file.txt”)

    B

    String path=”c:/java/example/”Filefile1=newFile(path,”oldfile.txt”)

    C

    File dir 1=new File(“c://java//example”)Filefile1=newFile(dir1,”oldfile.txt”)

    D

    File file 1=new File(“c:/java//example/file.txt”)


    正确答案: B,C
    解析: 暂无解析