单选题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.c

题目
单选题
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.


相似考题

4.【Java代码】import Java.util.ArrayList;import java.util.List;(1) class AbstractFile{protected String name;public void printName(){System.out.println(name);}public abstract boolean addChild(AbstractFile file);public abstract boolean removeChild(AbstractF ile file);public abstract List<AbstractFile> getChildren();}class File extends AbstractFile{public File(String name){this.name=name;}public boolean addChild(AbstractFile file){return false;}public boolean removeChild(AbstractFile file){return false;}public List<AbstractFile> getChildren(){return (2) ;}}class Folder extends AbstractFile{private List <AbslractFile> childList;public Folder(String name){this.name=name;this.childList=new ArrayList<AbstractFile>();}public boolean addChild(AbstractFile file) { return childList.add(file);}public boolean removeChild(AbstractFile file){return childList.remove(file);}public (3) <AbstractFile> getChildren(){return (4) ;}}public class Client{public static void main(String[] args){//构造一个树形的文件/目录结构AbstractFile rootFolder= new Folder("c:\\ ");AbstractFile compositeFolder=new Folder("composite");AbstractFile windowsFolder=new Folder("windows");AbstractFile file=new File("TestComposite.java");rootFolder.addChild(compositeFolder) ;rootFolder.addChild(windowsFolder);compositeFolder.addChild(file) ;//打印目录文件树printTree(rootFolder);}private static void printTree(AbslractFile ifile){ifile.printName();List <AbslractFile> children=ifile.getChildreno:if(children==null) return;for (AbstractFile file:children) {(5) ;}}}该程序运行后输出结果为:c:\compositeTestComposite.javaWindows

更多“单选题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.c”相关问题
  • 第1题:

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

    A.Compilation fails.

    B.Nothing is added to the file system.

    C.Only a new file is created on the file system.

    D.Only a new directory is created on the file system.

    E.Both a new file and a new directory are created on the file system.


    参考答案:B

  • 第2题:

    下面程序的运算结果是()。includeusing namespace std;class A{public:virtual void f

    下面程序的运算结果是( )。 #include<iostream> using namespace std; class A { public: virtual void fun()=0; }; class B:public A } public: void fun() {cout<<"new file"<<" ";} }; class C:public A { public: void fun() { cout<<"open file"<<" ";} }; void main() { A a, * p; B b;C c; p=&c; p->fun(); p=&b; }

    A.new file open file

    B.new file new file

    C.编译出错

    D.open file new file


    正确答案:C
    解析:语句Aa,*p;用抽象类说明了一个对象,这是不允许的。若把其改为A*p;则程序运行结果为D。

  • 第3题:

    下列程序要求将source.txt文件中的字符,通过文件输入/输出流复制到另一个dest.txt文件中。请将程序补充完整。

    注意:不改动程序结构,不得增行或删行。

    import java.io.*;

    public class ex2

    {

    public static void main(String[] args) throws IOException

    {

    File inputFile;

    File outputFile;

    FileInputStream in;

    FileOutputStream out;

    int c;

    inputFile=new File("source.txt");

    utputFile=new File("dest.txt");

    in=new FileInputStream(inputFile);

    ______(outputFile);

    while((c=in.read())!=-1)

    ______;

    in.close();

    out.close();

    }

    }


    正确答案:out=new FileOutputStream out.write?
    out=new FileOutputStream out.write? 解析:本题主要考查Java中的IO操作。第一空应填写out=new FileOutputStream。Java中要将一个文件中的内容写入到另一个文件中,需要知道文件读写操作。程序中已经声明了FileInputStream的对象in,套接File类的对象inputFile来进行读入的操作,我们还需要声明 FileOutputStream类的对象out,来套接File类的对象outputFile进行读出的操作。第二空应填写out.write(c)。程序此处要求进行文字写入。在程序的前一个步骤,已经调用FileInputStream类的read方法,将文件中的内容以单字节的方式读入到流中,所以我们在这里要调用FileOutputStream类的write方法,将流中的内容写出。

  • 第4题:

    现有一个文件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

  • 第5题:

    下列程序的运行结果是______。 package ch1; import java.io. *; public class ex28 { public static void main (String args [] ) throws IOException { try { File f1 = new File("ch1\\dir28"); f1.mkdir(); File f2 = new File(f1, "file59.txt"); FileOutputStream fos = new FileOutputStream(f2); for(int i = 0; i < 2; i++) { String s= i + "times"; byte[] b = s.getBytes(); fos.write(b,0,b.length); } } catch(IOException ioe) { ioe.printStackTrace(); } } }

    A.在目录ch1下建立一个目录dir28,并且建立文件file28.txt,在文件中写入"Otimes 1 times"

    B.在目录ch1下建立一个目录dir28,并且建立文件file28.txt,在文件中写入“l times”

    C.在目录chi下建立一个目录dir28,并且建立文件file28.txt,在文件中写入“Otimes”

    D.抛出IOExceptin异常


    正确答案:A

  • 第6题:

    阅读下列说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

    【说明】

    现欲构造一文件/目录树,采用组合(Composite)设计模式来设计,得到的类图如6—8所示:

    【Java代码】

    import JavA.util.ArrayList;

    import JavA.util.List;(1)class AbstractFile{

    protected String name;

    public void printName(){System.out.println(name);}

    public abstract boolean addChild(AbstractFile file);

    public abstract boolean removeChild(AbstractFile file);

    public abstract ListgetChildren {};

    }

    class File extends AbstractFile{

    public File(String name)(this.name=name;}

    public boolean addChild(AbstractFile file){return false;}

    public boolean removeChild(AbstractFile file){return false;}

    public ListgetChildren(){return (2) ;)

    }

    clasS Folder extends AbstractFile{

    private ListchildList;

    public Folder(String name){

    thiS.name=name;

    this.childList=new ArrayList{};

    }

    public boolean addChild(AbstractFile file){return childList.add(file);}

    public boolean removeChild(AbstractFile file){return childList.remove(file);

    public (3)getChildren(){return (4) ;)

    }

    public class Client{

    public static void main(String[]args){

    //构造一个树形的文件/目录结构

    AbstractFile rootFolder=new Folder(“C:\”’);

    AbstractFile compositeFolder=new Folder(”composite”);

    AbstractFile windowsFolder=new Folder(”windows”);

    AbstractFile file=new File(”TestComposite.java”);

    rootFOlder.addChild (compositeFolder);

    rootFolder.addChiid(windowsFolder);

    compositeFolder.addChild(file);

    //打印目录文件树

    printTree(rootFolder);

    }

    private static void printTree(AbstractFile ifile){

    ifile.PrIntName();

    Listchildren:ifile.getChildren ();

    if(chiidren==null)return;

    for(AbstractFile file:children){(5) ;

    }

    }

    }

    该程序运行后输出结果为:

    C:\

    composite

    TestComposite.java

    Windows


    正确答案:(1)Abstract(2)null(3)List(4)childList(5)printTree(file)
    (1)Abstract(2)null(3)List(4)childList(5)printTree(file) 解析:Composite模式定义:将对象以树型结构组织起来,以达成“部分-整体”的层次结构,使得客户端对单个对象和组合对象的使用具有一致性。Composite比较容易理解,想到Composite就应该想到树型结构图。组合体内这些对象都有共同接口,当组合体一个对象的方法被调用执行时,Composite将遍历(Iterator)整个树形结构,寻找同样包含这个方法的对象并实现调用执行。AbstractFile为一个抽象文件类,其作用主要是实现对文件或者文件夹的抽象。文件类File继承自AbstractFile。File(stringname)为File类的一个属性,用于获取文件名称。Add-child方法用来给一个目录增加子目录或文件。Removechild方法用于删除一个目录的子目录或文件。Getchildren方法用于获取一个目录或文件,所以返回值类型应该是一个列表形式的AbstractFile,但文件本身不包括子目录,故返回NUIJIJ。Fold类表示一个文件夹,属性Folder用于获取文件夹名称,Getchildren方法返回值应为List型的AbstractFile对象指针。

  • 第7题:

    下面程序的结果是 ______。includeclass A{ public:virtual voidfun()=0{};};class

    下面程序的结果是 ______。 #include<iostream.h> class A{ public: virtual void fun()=0{}; }; class B:public A{ public: void fun () {cout<< "new file" ;} }; class C: public A{ public: void fun (){cout<<"open file"<< " " } }; class D: public A{ public: void fun () {cout<< "save file\n" ;} }; void main() { A a,*p; B b; C c; D d; p=&c; p->fun (); p=&b; p->fun (); p=&d; p->fun(); }

    A.new file open file save file

    B.new file new file new file

    C.编译出错

    D.open file new file save file


    正确答案:C

  • 第8题:

    public class test {  public static void main(String [] a) {  assert a.length == 1;  }  }  Which two will produce an AssertionError?()

    • A、 java test
    • B、 java -ea test
    • C、 java test file1
    • D、 java -ea test file1
    • E、 java -ea test file1 file2
    • F、 java -ea:test test file1

    正确答案:B,E

  • 第9题:

    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.

    正确答案:B

  • 第10题:

    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

  • 第11题:

    单选题
    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
    解析: 暂无解析

  • 第12题:

    单选题
    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
    解析: 暂无解析

  • 第13题:

    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

  • 第14题:

    阅读下面程序 import java.io.*; public class ByteStreamTest { public static void main(String[] args) { int[] myArray={10,20,30,40}; try { DataOutputStream dos=new DataOutputStream (new ______("ints.dat")); for(int i=0;i<myArray.length;i++)dos.writeInt(myArray[i]); dos.close(); System.out.println("Have written binary file ints.dat"); } catch(IOException ioe) { System.out.println("IOException"); } } } 为保证程序正确运行,在程序中下画线处应填人的代码是

    A.FileOutputStream

    B.ByteArrayOutputStream

    C.BufferedOutputStream

    D.FileWriter


    正确答案:A
    解析:二进制文件可作为FileOutputStream对象的构造方法的参数,而FileOutputStream对象作为DataOutputStream的构造方法的参数实现DataOutputStream类。在本程序中,ints.dat二进制文件应作为FileOutputStream对象构造方法的参数,然后FileOutputStream对象作为字节输出流的形式参数。

  • 第15题:

    在程序中,用户输入一个文件名,根据用户输入显示相应文件的信息。

    注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。

    ______java.io.*;

    public class basic

    {

    public static void main(String[] args)

    {

    InputStreamReader reader;

    BufferedReader in;

    System.out.println("请输入文件名: ");

    try

    {

    reader=new InputStreamReader(______);

    in=new BufferedReader(reader);

    String filename=in.readLine();

    File file=new File(filename);

    System.out.println("文件名:"+file.______);

    System.out.println("路径:"+file.getAbsolutePath());

    System.out.println("大小:"+file.length());

    }

    catch(Exception e)

    {

    e.printStackTrace();

    }

    }

    }


    正确答案:import System.in getName()
    import System.in getName() 解析:本题考查知识点:Java类库中常用类和接口、文件和文件I/0、输入输出。解题思路:题中reader从系统获得输入流,从这个流中得到用户输入的字符串作为文件名,找到文件,进而得到文件的相关信息。Java的类库需要引入以后才能使用,关键字import就是声明需要引入的类或包。因此第1个空的答案是import。Java的输入输出是以流的形式来完成的。InputStreamReader的对象reader从系统输入中读取输入流,保存在相应的缓冲区中,因此第2个空的答案是System.in。BufferedReader对象则是从这个缓冲区中读取数据,使用BufferedReader类的readLine()方法即可获得输入流中的一行输入。在Java程序中,文件作为类的一个实例来处理,File类具有很多与文件相关的方法,比如获得上级目录名(getParent()方法)、路径(getPath()方法)等,第3个空就是使用getName()方法获取文件的文件名。

  • 第16题:

    下列程序执行后的结果是______。 package ch1; import java.io.*; public class ex22 { static, String filename = "ch1\kfile22.txt"; public static void main(String[] args) { try { FileWriter fr = new FileWriter(filename); PrintWriter pr = new PrintWriter(fr); String name = "xiaoming"; String phone = "123456"; String age = "12"; pr.println(name + ',' + phone + ',' + age); pr.close(); fr.close(); } catch(IOException ioe) { ioe.printStackTrace() } } }

    A.在包ch1 中新建一个文件file22.txt, 并且在其中写入一行字符串“xiaomingl2345612”

    B.在包ch1中新建一个文件file22.txt,并且在其中写入一行字符串“xiaoming, 123456,12”

    C.在包chi中新建一个文件file22.txt,并且在其中写入一行字符串“xiaoming'’

    D.抛出IOException


    正确答案:B

  • 第17题:

    阅读下列说明和c++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

    【说明】

    现欲构造一文件/目录树,采用组合(Composite)设计模式来设计,得到的类图如6—7所示:

    【c++代码】

    include<1ist>

    include

    include

    using namespace std;

    class AbstractFile{

    protected:

    string name;//文件或目录名称

    public:

    void printName(){cout<*getChildren()=0; //获得一个目录的子目录或文件

    };

    class File:public AbstractFile{

    public:

    File(string name){ (1) =name;)

    void addChild(AbstractFile*file){return ;)

    void removeChiid(AbstractFile*file){return;}(2) getChildren(){return ( 3 ) ;}

    };

    class Folder:public AbstractFile{

    private:

    listchildList; //存储子目录或文件

    public:

    Folder(string name){ (4) =name;}

    void addChild(AbstractFile*file){childList.push back(file);}

    void removeChiid(AbstractFile*file)(chiidList.remove(file);}

    list*getChildren(){return (5) ;)

    };

    voidmain(){

    //构造一个树形的文件/目录结构

    AbstractFile*rootFolder=new Folder(“C:\\”);

    AbstractFile*compositeFolder=flew Folder(”composite”);

    AbstractFile*windowsFolder=new Folder(”windows”);

    AbstractFile*file=new File(”TestComposite.java”);

    rootFolder->addChild(compositeFolder);

    rootFolder->addChild (windowsFolder);

    compositeFolder->addChiid(file);

    )


    正确答案:(1)this一>name(2)list<AbstractFile*>*(3)NULL(4)this->name(5)&childList
    (1)this一>name(2)list<AbstractFile*>*(3)NULL(4)this->name(5)&childList 解析:Composite模式定义:将对象以树型结构组织起来,以达成“部分一整体”的层次结构,使得客户端对单个对象和组合对象的使用具有一致性。Composite比较容易理解,想到Composite就应该想到树形结构图。组合体内这些对象都有共同接口,当组合体一个对象的方法被调用执行时,Composite将遍历(Iterator)整个树形结构,寻找同样包含这个方法的对象并实现调用执行。AbstractFile为一个抽象文件类,其作用主要是实现对文件或者文件夹的抽象。文件类File继承自AbstractFile。File(stringname)为File类的一个属性,用于获取文件名称。Addchild方法用来给一个目录增加子目录或文件。Removechild方法用于删除一个目录的子目录或文件。Getchildren方法用于获取一个目录或文件,所以返回值类型应该是一个列表形式的AbstractFile,但文件本身不包括子目录,故返回NULL。Fold类表示一个文件夹,属性Fold.er用于获取文件夹名称,Getchildren方法返回值应为List型的AbstractFile对象指针。

  • 第18题:

    以下程序是一个简单文本处理器,菜单项可以打开、编辑、保存一个文件。文件内容显示在下面的文本区域中(提示,打开文件通过文件选择器来完成)。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。运行结果如下图所示。

    注意:不改动程序的结构,不得增行或删行。

    import java.awt.*;

    import java.awt.event.*;

    import java.io.* ;

    import javax.swing.*;

    class FileFrame. extends JFrame

    {

    File file;

    JTextPane textpane;

    FileInputStream readStream;

    JScrollPane scroll;

    public FileFrame()

    {

    super ("文件浏览");

    JMenu fileM = new JMenu("文件");

    OpenAction pen = new OpenAction ();

    SaveAction clear = new SaveAction ();

    ExitAction exit = new ExitAction();

    JMenuBar mb = new JMenuBar();

    fileM.add(open);

    fileM.add(clear);

    fileM.add(exit);

    mb.add(fileM);

    textpane=new JTextPane();

    scroll=new JScrollPane(textpane);

    getContentPane().add(scroll);

    getContentPane().addJMenuBar(mb);

    }

    class OpenAction extends AbstractAction

    {

    public OpenAction ()

    {

    super("打开");

    }

    public void actionPerformed( ActionEvent e )

    {

    JFileChooser chooser=new JFileChooser();

    int state=chooser.showOpenDialog(null);

    file=chooser.selectedFile();

    if(file!=null&&state==JFileChooser.APPROVE_OPTION)

    {

    try

    {

    readStream=new FileInputStream(file);

    textpane.read(readStream, this);

    readStream.close();

    }

    catch(IOException ioE){}

    }

    }

    }

    class SaveAction extends AbstractAction

    {

    public SaveAction()

    {

    super("保存");

    }

    public void actionPerformed( ActionEvent e )

    {

    if(file==null)

    return;

    try{

    FileWriter ut = new FileWriter(file);

    out.read(textpane.getText());

    out.close();

    }

    catch (IOException ioE)

    {}

    }

    }

    class ExitAction extends AbstractAction

    {

    public ExitAction()


    正确答案:①setJMenuBar(mb) ②file=chooser.getSelectedFile() ③out.write(textpane.getText())
    ①setJMenuBar(mb) ②file=chooser.getSelectedFile() ③out.write(textpane.getText()) 解析:构造方法FileFrame()中初始化了程序界面,菜单“fileM”中添加了3个菜单项“打开”、“保存”和“退出”,并为这3个菜单项添加了相应的事件。“textpane”是一个文本编辑面板,其上可以显示和修改文本。openAction类定义了用户选择“打开”菜单的事件。用户选择“打开”,程序向用户显示文件选择器“chooser”,使用户通过图形化的方式选择文件。根据用户选择的结果,生成File类的实例“file”。语句“textpane.read(readStream,this)”读取文件内容并显示在“textpane”中。 SaveAction定义了用户选择“保存”菜单的事件。在SaveAction类中,程序调用FileWriter的写文件方法将“textpane”中的内容输出到文件中。
    玻璃面板(glassPane)、内容面板(contentPane)、菜单条(JMenuBar)共同组成根面板。getContentPane()获得的是顶层容器的内容面板而不是根面板,所以不能在其中添加菜单条。因此第 1 条下划线处应该改为 setJMenuBar(mb),将“mb”设置为根面板的菜单条。
    第2处和第3处改错,主要考查对文件选择和文件输出的基本操作的掌握情况。这些常用的类和常用的方法只有在多次练习之后才能熟练掌握。

  • 第19题:

    ( 11 )请在下列程序的空白处,填上适当的内容:

    Import java. awt. *;

    Import java. util. *;

    Class BufferTest{

    Public static void main(string args[])

    Throws IOException{

    FileOutputStream unbuf=

    new FileOutputStream( “ test.one ” ) ;

    BufferedOutputStream buf=

    new 【 11 】 (new FileOutputStream( “ test.two ” ));

    System.out.println

    ( “ write file unbuffered: ” + time(unbuf) + “ ms ” );

    System.out.println

    ( “ write file buffered: ” + time(buf) + “ ms ” );

    }

    Static int time (OutputStream os)

    Throws IOException{

    Date then = new Date();

    for (int i=0; i<50000; i++){

    os.write(1);

    }

    }

    os.close();

    return(int)(()new Date()).getTime() - then.getTime());

    }


    正确答案:

  • 第20题:

    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

  • 第21题:

    Given that file is a reference to a File object that represents a directory, which code fragments will succeed in obtaining a list of the entries in the directory?()  

    • A、Vector filelist = ((Directory) file).getList();
    • B、String[] filelist = file.directory();
    • C、Enumeration filelist = file.contents();
    • D、String[] filelist = file.list();
    • E、Vector filelist = (new Directory(file)).files();

    正确答案:D

  • 第22题:

    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

  • 第23题:

    单选题
    Given that the current directory is empty, and that the user has read and write privileges to the current directory, and the following: Which statement is true?()
    A

    Compilation fails.

    B

    Nothing is added to the file system.

    C

    Only a new file is created on the file system.

    D

    Only a new directory is created on the file system.

    E

    Both a new file and a new directory are created on the file system.


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

  • 第24题:

    多选题
    public class test {  public static void main(String [] a) {  assert a.length == 1;  }  }  Which two will produce an AssertionError?()
    A

    java test

    B

    java -ea test

    C

    java test file1

    D

    java -ea test file1

    E

    java -ea test file1 file2

    F

    java -ea:test test file1


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