单选题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();
单选题
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();
参考解析
解析:
暂无解析
相关考题:
【C++代码】#include list#include iostream#include stringusing namespace std;class AbstractFile{protected:string name; //文件或目录名称public:void printName(){coutname;} //打印文件或目录名称virtual void addChild(AbstractFile *file)=0; //给一个目录增加子目录或文件}virtual void removeChild(AbstractFile *file)=0; //删除一个目录的子目录或文件virtual listAbstractFile* *getChildren()=0; //获得一个目录的子目录或文件};class File:public AbstractFile{public:File(string name) {(1) = name;}void addChild(AbstractFile *file){return;}void removeChild(AbstractFile *file){return;}(2) getChildren(){return (3) ;}};class Folder :public AbstractFile{private:list AbstractFile* childList: //存储子目录或文件public:Folder(string name){ (4) name;}void addChild(AbstractFile*file){childList.push_back(file);}void removeChild(AbstractFile*file){childList.remove(file);}listAbstractFile**getChildren(){return (5) ;}};void main(){//构造一个树形的文件/目录结构AbstractFile *rootFolder=new Folder("c:\\ ");AbstractFile*compositeFolder=new Folder("composite");AbstractFile *windowsFolder=new Folder("windows");AbstractFile*file=new File("TestCompositejava");rootFolder-addChild(compositeFolder);rootFolder-addChild(windowsFolder);compositeFolder-addChild(file);}
【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 ListAbstractFile 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 ListAbstractFile getChildren(){return (2) ;}}class Folder extends AbstractFile{private List AbslractFile childList;public Folder(String name){this.name=name;this.childList=new ArrayListAbstractFile();}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
下列InputStream构造方法正确的是()。 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”))
要想以读方式打开文件“D:\File.txt”,以下不能实现目的的语句是()。A、ifstreaminf("D:\\FilEtxt",ios::in);B、ifstreaminf("D:\\File.txt");C、ofstreaminf("D:\\File.txt",ios::out);D、fstreaminf("D:\\File.txt",ios::in|ios::out);
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);
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”);
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();
阅读下列说明和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:\compositeTestComposite.javaWindows
对于如下程序: #include main( ) { FILE *fp; fp=fopen(“file.txt”,“w”); fprintf(fp,“%s”,“xyz”); fclose(fp); } 若文件file.txt中原有的内容为good,则运行该程序以后,文件file.txt中的内容为()
创建一个向文件“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、%@ 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”%
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:/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”)
Which of the following commands changes a file characteristic so that it cannot be seen with astandard directory query? ()A、attrib file.txt +hB、attrib file.txt +rC、ren file.txtD、attrib file.txt +s
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”));
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();
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.
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”);
多选题Which two create an InputStream and open file the “file.txt” for reading? ()AInputStream in=new FileReader(“file.txt”);BInputStream in=new FileInputStream(“file.txt”);CInputStream in=new InputStreamFileReader (“file.txt”, “read”);DFileInputStream in=new FileReader(new File(“file.txt”));EFileInputStream in=new FileInputStream(new File(“file.txt”));
单选题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”);
填空题对于如下程序: #include main( ) { FILE *fp; fp=fopen(“file.txt”,“w”); fprintf(fp,“%s”,“xyz”); fclose(fp); } 若文件file.txt中原有的内容为good,则运行该程序以后,文件file.txt中的内容为()
多选题创建一个向文件“file.txt”追加内容的输出流对象的语句有()。AFileOutputStream out=new FileOutputStream(“file.txt”,true);BOutputStream out=new FileOutputStream(“file.txt”,“append”);COutputStream out=new FileOutputStream(“file.txt”);DFileOutputStream out=new FileOutputStream(new file(“file.txt”));EOutputStream out=new FileOutputStream(new File(“file.txt”),true.;
单选题下列语句正确的有()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”%
单选题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();
多选题Which two construct an OutputSream that appends to the file “file.txt”? ()AOutputStream out=new FileOutputStream(“file.txt”);BOutputStream out=new FileOutputStream(“file.txt”, “append”);CFileOutputStream out=new FileOutputStream(“file.txt”, true);DFileOutputStream out=new FileOutputStream(new file(“file.txt”));EOutputStream out=new FileOutputStream(new File(“file.txt”)true);
单选题Which of the following commands changes a file characteristic so that it cannot be seen with astandard directory query? ()Aattrib file.txt +hBattrib file.txt +rCren file.txtDattrib file.txt +s
单选题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:/java/example/file.txt建立File对象file1可以采用()语句序列。AFile file 1=new File(“c://java//example//file.txt”)BString path=”c:/java/example/”Filefile1=newFile(path,”oldfile.txt”)CFile dir 1=new File(“c://java//example”)Filefile1=newFile(dir1,”oldfile.txt”)DFile file 1=new File(“c:/java//example/file.txt”)