用“new FileOutputStream(“data.txt”,true)”创建一个FileOutputStream实例对象,则下面()说法是正确的。A、如果文件“data.txt”存在,则将抛出IOException异常B、如果文件“data.txt”存在,则将在文件的末尾开始添加新内容C、如果文件“data.txt”存在,则将覆盖掉文件中已有的内容D、如果文件“data.txt”不存在,则将抛出IOException异常

用“new FileOutputStream(“data.txt”,true)”创建一个FileOutputStream实例对象,则下面()说法是正确的。

  • A、如果文件“data.txt”存在,则将抛出IOException异常
  • B、如果文件“data.txt”存在,则将在文件的末尾开始添加新内容
  • C、如果文件“data.txt”存在,则将覆盖掉文件中已有的内容
  • D、如果文件“data.txt”不存在,则将抛出IOException异常

相关考题:

本题的功能是将文件java2.java复制为文件java2.java.bak。 importjava.io.*; public class java2{ public static void main(String sarg[]){ try{File file=new File("java2.java.bak"); ; FilelnputStream rfile=new FilelnputStream("ja- va2.java"); FileOutputStream wfile=new FileOutputStream ("java2.java.bak"); int c; while( ) wfile.write((char)c); rfile.close; wfile.close; }catch(Exception e){System.out.println("读取文 件的时候发生错误!");} System.out.println("复制操作完成!"); } }

( 14 )有如下程序:#includeusing namespace std;class DA{int k;public:DA ( int x=1 ) : k ( x ) {}~ DA () {cout};int main () {DA d[]={DA ( 3 ) ,DA ( 3 ) ,DA ( 3 ) };DA* p=new DA[2];delete[]p;return0;}这个程序的输出结果是 【 14 】 。

请完成下列Java程序:读取自己的源文件并把它压缩成GZIP文件。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。import java.io.*;import java.util.zip.*;public class exl6 2 {public static void main{String[] arg) {ex16_2 obj16_2 = new ex16_2();obj16_2.doZip("ex16_2.java","ex16_2.gzip")}public void doZip(String strIn,String strOutFileInputStream in;FileOutputStream out;GZIPOutputStream gzip;int nFileLength;byte[] barray = new byte[10];try {in = new FileInputStream(strIn);out = new FileOutputStream(strOut);gzip = new GZIPOutputStream(out);while((nFileLength = in.read(barray, 0 barray.length)) > 0)_____________________;______________________;gzip.close();} catch(Exception e) {e.printStackTrace();}}}

有如下程序:includeusing namespace std;class DA{int k;public:DA(int x=1):k(x){}~ 有如下程序: #include<iostream> using namespace std; class DA{ int k; public: DA(int x=1):k(x){} ~DA(){cout<<k;} }; int main(){ DAd[]={DA(3),DA(3),DA(3)}; DA*p=new DA[2]; delete[]p; return(); } 这个程序的输出结果是( )。A.111B.333C.11333D.11133

选择正确的语句填在下列程序的横线处,使程序正常运行。 package ch1; import java. io. *; import j ava. util. *; class C45 implements Seritizable ______Public Thread t = new Thread(new T45(), "t"); public intcnt = 0; public C45() { t. start ( ) class T45 implements Runnable public int[] a = new int[4]; public void run() { for(int i - 0; i < 4; i++) { a[i] - i +4; } } } public class ex45 { static String fileName = "ch1\\file45.txt"; public static void main(String[] args) throws Exception { C45 bj = new C45 (); FileOutputStream fos = new FileOutputStream(fileName); ObjectOutputStream os = new ObjectOutputStream(fos); oos. writeObject (obj); oos.clese (); fos.close (); System. out, println (obj . toString ( ) ); } }A.transientB.protectedC.packageD.final

有如下程序;includeusing namespace std;class DA {int k;public:DA(int x=1):k (x){ 有如下程序; #include<iostream> using namespace std; class DA { int k; public: DA(int x=1):k (x){} ~DA( ){cout<<k;} }; int main( ){ DA d[]={DA(3),DA(3),DA(3)}; DA *p=new DA[2]; delete []p; return (); } 这个程序的输出结果是( )。A.111B.333C.11333D.11133

阅读下面写文件的程序 import java.io.*: public class WriteFile{ public static void main(String[] A) { int[] myArray={10,20,30,40}; try { FileOutputStream f=new FileOutputStream("ints.dat"); DataOutputStream ______ =new DataOutputStream(f); 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.myArrayB.dosC.ioeD.ints

下列程序将Date对象写入文件file42.txt中,选择正确的语句填入下列程序中的横线处。 package ch1; impbrt java. io. *; import java. util. *; public class ex42 { static String fileName = "ch1\\file42.txt"; static Date date = null; public static void main(String[] args) { date = new Date(); try { FileOutputStream fos = new FileOutputStream(file Name); ObjectOutStream os = new ObjectOutputStream(fos); oos.______; oos.close(); fos.close(); System.out.println(date.toString()); } catch(Exception e) { System.out.println(e.getMessage()); } } }A.writeObject()B.writeObject(date)C.write(date)D.writeByte(date)

( 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; i50000; i++){os.write(1);}}os.close();return(int)(()new Date()).getTime() - then.getTime());}

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

在J2EE中,利用下列构造函数准备对文件abc.txt操作,但文件abc.txt在当前目录不存在,不会产生运行时错误的是()。 A、BufferedReader  breader=new BufferedReader(new FileReader("abc.txt"));B、PrintWriter out = new PrintWriter(new FileWriter(“abc.txt”),true);C、FileInputStream fin = new FileInputStream(“abc.txt”);D、OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(“abc.txt”));

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

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.txt”的长度为100字节,那么当正常运行语句“OutputStream f = new FileOutputStream(new File(“a.txt”));”之后,文件“a.txt”的长度变为0字节。()

Which constructs a DataOutputStream?()A、 New dataOutputStream(“out.txt”);B、 New dataOutputStream(new file(“out.txt”));C、 New dataOutputStream(new writer(“out.txt”));D、 New dataOutputStream(new FileWriter(“out.txt”));E、 New dataOutputStream(new OutputStream(“out.txt”));F、 New dataOutputStream(new FileOutputStream(“out.txt”));

import java.io.*;  public class Forest implements Serializable {  private Tree tree = new Tree();  public static void main(String [] args) {  Forest f= new Forest();  try {  FileOutputStream fs = new FileOutputStream(”Forest.ser”);  ObjectOutputStream os = new ObjectOutputStream(fs);  os.writeObject(f); os.close();  } catch (Exception ex) { ex.printStackTrace(); }  }  }  class Tree { }  What is the result?() A、 Compilation fails.B、 An exception is thrown at runtime.C、 An instance of Forest is serialized.D、 A instance of Forest and an instance of Tree are both serialized.

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.

单选题用“new FileOutputStream(“data.txt”,true)”创建一个FileOutputStream实例对象,则下面()说法是正确的。A如果文件“data.txt”存在,则将抛出IOException异常B如果文件“data.txt”存在,则将在文件的末尾开始添加新内容C如果文件“data.txt”存在,则将覆盖掉文件中已有的内容D如果文件“data.txt”不存在,则将抛出IOException异常

单选题Which constructs a DataOutputStream?()A New dataOutputStream(“out.txt”);B New dataOutputStream(new file(“out.txt”));C New dataOutputStream(new writer(“out.txt”));D New dataOutputStream(new FileWriter(“out.txt”));E New dataOutputStream(new OutputStream(“out.txt”));F New dataOutputStream(new FileOutputStream(“out.txt”));

判断题假设文件“a.txt”的长度为100字节,那么当正常运行语句“OutputStream f = new FileOutputStream(new File(“a.txt”));”之后,文件“a.txt”的长度变为0字节。()A对B错

单选题在下列程序的空白处,应填入的正确选项是(  )。import java.io.*;public class ObjectStreamTest{public static void main(string args[])throws IOException{ ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("serial.bin")); Java.until.Date d=new Java.until.Date(); oos.______(); ObjectInputStream ois=new ObjectlnputStream(new FileOutputStream("serial.bin")); try{ java.until.date restoredDate=(Java.until.Date)ois.readObject(); System.out.println("read object back from serial.bin file:"+restoredDate); } catch(ClassNotFoundException cnf){ System.out.println("class not found"); }}AreadObjectBWriterCBufferedWriterDwriteObject

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

单选题Which statements are true, given the code new FileOutputStream("data", true) for creating an object of class FileOutputStream?()AFileOutputStream has no constructors matching the given arguments.BAn IOExeception will be thrown if a file named data already exists.CAn IOExeception will be thrown if a file named data does not already exist.DIf a file named data exists, its contents will be reset and overwritten.EIf a file named data exists, output will be appended to its current contents.

单选题import java.io.*;  public class Forest implements Serializable {  private Tree tree = new Tree();  public static void main(String [] args) {  Forest f= new Forest();  try {  FileOutputStream fs = new FileOutputStream(”Forest.ser”);  ObjectOutputStream os = new ObjectOutputStream(fs);  os.writeObject(f); os.close();  } catch (Exception ex) { ex.printStackTrace(); }  }  }  class Tree { }  What is the result?()A Compilation fails.B An exception is thrown at runtime.C An instance of Forest is serialized.D A instance of Forest and an instance of Tree are both serialized.

多选题创建一个向文件“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.;

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