itgle.com

单选题Which gets the name of the parent directory file “file.txt”?()AString name= File.getParentName(“file.txt”);BString name= (new File(“file.txt”)).getParent();CString name = (new File(“file.txt”)).getParentName();DString name= (new File(“file.txt”)).getPa

题目
单选题
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();


相似考题

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 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””相关问题
  • 第1题:

    WhichtwoconstructanOutputSreamthatappendstothefile“file.txt”?()

    A.OutputStreamout=newFileOutputStream(“file.txt”);

    B.OutputStreamout=newFileOutputStream(“file.txt”,“append”);

    C.FileOutputStreamout=newFileOutputStream(“file.txt”,true);

    D.FileOutputStreamout=newFileOutputStream(newfile(“file.txt”));

    E.OutputStreamout=newFileOutputStream(newFile(“file.txt”)true);


    参考答案:C, E

  • 第2题:

    Whichgetsthenameoftheparentdirectoryfile“file.txt”?()

    A.Stringname=File.getParentName(“file.txt”);

    B.Stringname=(newFile(“file.txt”)).getParent();

    C.Stringname=(newFile(“file.txt”)).getParentName();

    D.Stringname=(newFile(“file.txt”)).getParentFile();

    E.Directorydir=(newFile(“file.txt”)).getParentDir();Stringname=dir.getName();


    参考答案:B

  • 第3题:

    对于如下程序:  #include    main( )  {    FILE *fp;    fp=fopen(“file.txt”,“w”);    fprintf(fp,“%s”,“xyz”);    fclose(fp);  }  若文件file.txt中原有的内容为good,则运行该程序以后,文件file.txt中的内容为()


    正确答案:xyz

  • 第4题:

    下列语句正确的有()

    • A、<%@ include file=”head.jsp”%> 
    • B、<% String url=”head.jsp”;%><%@ include file=”url”%> 
    • C、<%@ include file=”head.jsp”?name=”lovo”%> 
    • D、<%String companyName=”lovo”;%>%@include file”head.jsp”?name=‟companyName”% 

    正确答案:B

  • 第5题:

    为文件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

  • 第6题:

    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

  • 第7题:

    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

  • 第8题:

    多选题
    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”));


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

  • 第9题:

    填空题
    对于如下程序:  #include    main( )  {    FILE *fp;    fp=fopen(“file.txt”,“w”);    fprintf(fp,“%s”,“xyz”);    fclose(fp);  }  若文件file.txt中原有的内容为good,则运行该程序以后,文件file.txt中的内容为()

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

  • 第10题:

    单选题
    下列语句正确的有()
    A

    <%@ include file=”head.jsp”%> 

    B

    <% String url=”head.jsp”;%><%@ include file=”url”%> 

    C

    <%@ include file=”head.jsp”?name=”lovo”%> 

    D

    <%String companyName=”lovo”;%>%@include file”head.jsp”?name=‟companyName”% 


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

  • 第11题:

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

  • 第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题:

    Whatwritesthetext“”totheendofthefile“file.txt”?()

    A.OutputStreamout=newFileOutputStream(“file.txt”); Out.writeBytes(“/n”);

    B.OutputStreamos=newFileOutputStream(“file.txt”,true); DataOutputStreamout=newDataOutputStream(os);out.writeBytes(“/n”);

    C.OutputStreamos=newFileOutputStream(“file.txt”); DataOutputStreamout=newDataOutputStream(os);out.writeBytes(“/n”);

    D.OutputStreamos=newOutputStream(“file.txt”,true); DataOutputStreamout=newDataOutputStream(os);out.writeBytes(“/n”);


    参考答案:B

  • 第14题:

    阅读下列说明和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对象指针。

  • 第15题:

    创建一个向文件“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

  • 第16题:

    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

  • 第17题:

    Which of the following commands changes a file characteristic so that it cannot be seen with astandard directory query? ()

    • A、attrib file.txt +h
    • B、attrib file.txt +r
    • C、ren file.txt
    • D、attrib file.txt +s

    正确答案:A

  • 第18题:

    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

  • 第19题:

    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

  • 第20题:

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

  • 第21题:

    多选题
    创建一个向文件“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
    解析: 暂无解析

  • 第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 of the following commands changes a file characteristic so that it cannot be seen with astandard directory query? ()
    A

    attrib file.txt +h

    B

    attrib file.txt +r

    C

    ren file.txt

    D

    attrib file.txt +s


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

  • 第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
    解析: 暂无解析