用“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异常

相似考题
更多“用“new FileOutputStream(“da”相关问题
  • 第1题:

    选择正确的语句填在下列程序的横线处,使程序正常运行。 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.transient

    B.protected

    C.package

    D.final


    正确答案:A

  • 第2题:

    阅读下面写文件的程序 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.myArray

    B.dos

    C.ioe

    D.ints


    正确答案:B

  • 第3题:

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

    }


    正确答案:

  • 第4题:

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

    正确答案:B,D

  • 第5题:

    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.

    正确答案:E

  • 第6题:

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

    正确答案:F

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

  • 第9题:

    单选题
    在下列程序的空白处,应填入的正确选项是(  )。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"); } }
    A

    readObject

    B

    Writer

    C

    BufferedWriter

    D

    writeObject


    正确答案: A
    解析:
    java.io包中,提供了0bjectInputStream和ObjectOutputStream将数据流功能扩展至可读写对象。在ObjectInputStream中用readObject()方法可以直接读取一个对象,0bjectOutputStream中用writeObject()方法可以直接将对象保存到输出流中。B项和C项,Writer和BufferedWriter都为java.io包中的类。

  • 第10题:

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


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

  • 第11题:

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

  • 第12题:

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

  • 第13题:

    有如下程序;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.111

    B.333

    C.11333

    D.11133


    正确答案:C
    解析:此题考查的是析构函数和对象的生存期。在主函数中,首先定义了一个DA类对象数组d,从初始化列表中可以看出,它包含3个对象;然后通过new运算符动态创建了一个DA类的对象数组,并将首地址赋给DA类指针p;接着通过delete[]运算符销毁指针p所指向的数组,故此时会输出“11”。最后函数结束,销毁前面定义的对象数组d,会输出“333”。故最后的输出结果是11333。

  • 第14题:

    下列程序将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)


    正确答案:B

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

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


    正确答案:正确

  • 第18题:

    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.

    正确答案:B

  • 第19题:

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

    如果文件“data.txt”存在,则将抛出IOException异常

    B

    如果文件“data.txt”存在,则将在文件的末尾开始添加新内容

    C

    如果文件“data.txt”存在,则将覆盖掉文件中已有的内容

    D

    如果文件“data.txt”不存在,则将抛出IOException异常


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

  • 第20题:

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

    B


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

  • 第21题:

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

  • 第22题:

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


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

  • 第23题:

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