Thefilefile.txt”existsonthefilesystemandcontsinsASCIItext.Given:try{Filef=newFile(file.txt”);OutputStreamout=newFileOutputStream(f,true);}catch(IOException){}Whatistheresult?() A.Thecodedoesnotcompile.B.Thecoderunsandnochangeismadetothefile.C.Thecoderunsandsetsthelengthofthefileto0.D.Anexceptionisthrownbecausethefileisnotclosed.E.Thecoderunsanddeletesthefilefromthefilesystem.

Thefilefile.txt”existsonthefilesystemandcontsinsASCIItext.Given:try{Filef=newFile(file.txt”);OutputStreamout=newFileOutputStream(f,true);}catch(IOException){}Whatistheresult?()

A.Thecodedoesnotcompile.

B.Thecoderunsandnochangeismadetothefile.

C.Thecoderunsandsetsthelengthofthefileto0.

D.Anexceptionisthrownbecausethefileisnotclosed.

E.Thecoderunsanddeletesthefilefromthefilesystem.


相关考题:

importjava.io.*;publicclassForestimplementsSerializable{privateTreetree=newTree();publicstaticvoidmain(String[]args){Forestf=newForest();try{FileOutputStreamfs=newFileOutputStream(”Forest.ser”);ObjectOutputStreamos=newObjectOutputStream(fs);os.writeObject(f);os.close();}catch(Exceptionex){ex.printStackTrace();}}}classTree{}Whatistheresult?()A.Compilationfails.B.Anexceptionisthrownatruntime.C.AninstanceofForestisserialized.D.AinstanceofForestandaninstanceofTreearebothserialized.

staticvoidtest()throwsError{if(true)thrownewAssertionError();System.out.print(”test);}publicstaticvoidmain(String[]args){try{test();}catch(Exceptionex){System.out.print(”exception);}System.out.print(”elld);}Whatistheresult?()A.endB.Compilationfails.C.exceptionendD.exceptiontestendE.AThrowableisthrownbymain.F.AnExceptionisthrownbymain.

importjava.io.IOException;publicclassExceptionTest(publicstaticvoidmain(String[]args)try(methodA();)catch(IOExceptione)(system.out.printIn(CaughtIOException”);)catch(Exceptione)(system.out.printIn(CaughtException”);))publicvoidmethodA(){thrownewIOException();}Whatistheresult?()A.Thecodewillnotcompile.B.Theoutputiscaughtexception.C.TheoutputiscaughtIOException.D.Theprogramexecutesnormallywithoutprintingamessage.

publicclassAextendsThread{A(){setDaemon(true);}publicvoidrun(){(newB()).start();try{Thread.sleep(60000);}catch(InterruptedExceptionx){}System.out.println(Adone”);}classBextendsThread{publicvoidrun(){try{Thread.sleep(60000);}catch(InterruptedExceptionx){}System.out.println(Bdone”);}}publicstaticvoidmain(String[]args){(newA()).start();}}Whatistheresult?()A.AdoneB.BdoneC.AdoneBdoneD.BdoneAdoneE.Thereisnoexceptionthattheapplicationwillprintanything.F.Theapplicationoutputs“Adone”and“Bdone”,innoguaranteedorder.

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);

importjava.io.IOException;publicclassExceptionTest(publicstaticvoidmain(Stringargs)try(methodA();)catch(IOExceptione)(system.out.printIn(CaughtIOException”);)catch(Exceptione)(system.out.printIn(CaughtException”);))publicvoidmethodA(){thrownewIOException();}Whatistheresult?()A.Thecodewillnotcompile.B.Theoutputiscaughtexception.C.TheoutputiscaughtIOException.D.Theprogramexecutesnormallywithoutprintingamessage.

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”);

为了向文件hello.txt尾部追加数据,下列哪个是正确创建指向hello.txt的流()A.try{ OutputStream out=new FileOutputStream("hello.txt"); }catch(IOException e) { }B.try{ OutputStream out=new FileOutputStream("hello.txt",true); }catch(IOException e) { }C.try{ OutputStream out=new FileOutputStream("hello.txt",false); }catch(IOException e) { }D.try{ OutputStream out=new OutputStream("hello.txt",true); }catch(IOException e) { }

17、下面哪些选项能够创建一个OutputStream流,并且可以将内容附加到“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(“file.txt”);