在J2EE中,假如在当前目录下不存在employee.txt文件。在当前目录下的一个类文件的main函数只包含如下代码:  try {                                                             PrintWriter out = new PrintWriter(new FileOutputStream(“employee.txt”));      String name = “jb-aptech”;                      

题目

在J2EE中,假如在当前目录下不存在employee.txt文件。在当前目录下的一个类文件的main函数只包含如下代码:  try {                                                             PrintWriter out = new PrintWriter(new FileOutputStream(“employee.txt”));      String name = “jb-aptech”;                                    double salary = 75000;                                            out.print(name);                                                out.print(„ „);                                                out.println(salary);                                        }                                                              catch(Exception e)                                               System.out.println("文件没有发现!");                                                        在DOS控制台上编译并且运行该类文件。下面的描述正确的是()。 

  • A、使用java命令运行该类文件,将在控制台上打印:"文件没有发现!"
  • B、运行结束后打开employee.txt,会发现该文件什么也没有
  • C、运行结束后打开employee.txt,会发现文件中有这样的文本:“jb-aptech 75000”
  • D、在第7行后加上代码:out.close(),编译并运行该类文件后,打开employee.txt,才会发现文件中有这样的文本:“jb-aptech 75000.0”
  • E、把第2行代码改为: PrintWriter out = new PrintWriter(new FileOutputStream(“employee.txt”),true);  编译并运行该类文件后,打开employee.txt,才会发现文件中有这样的文本:“jb-aptech 75000.0”

相似考题
参考答案和解析
正确答案:B,D,E
更多“在J2EE中,假如在当前目录下不存在employee.txt文件。在当前目录下的一个类文件的main函数只包含如下代码:  try {                                                             PrintWriter out = new PrintWriter(new FileOutputStream(“employee.txt”));      String name = “jb-aptech”;                       ”相关问题
  • 第1题:

    在程序中,用户输入一个文件名,根据用户输入显示相应文件的信息。

    注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。

    ______java.io.*;

    public class basic

    {

    public static void main(String[] args)

    {

    InputStreamReader reader;

    BufferedReader in;

    System.out.println("请输入文件名: ");

    try

    {

    reader=new InputStreamReader(______);

    in=new BufferedReader(reader);

    String filename=in.readLine();

    File file=new File(filename);

    System.out.println("文件名:"+file.______);

    System.out.println("路径:"+file.getAbsolutePath());

    System.out.println("大小:"+file.length());

    }

    catch(Exception e)

    {

    e.printStackTrace();

    }

    }

    }


    正确答案:import System.in getName()
    import System.in getName() 解析:本题考查知识点:Java类库中常用类和接口、文件和文件I/0、输入输出。解题思路:题中reader从系统获得输入流,从这个流中得到用户输入的字符串作为文件名,找到文件,进而得到文件的相关信息。Java的类库需要引入以后才能使用,关键字import就是声明需要引入的类或包。因此第1个空的答案是import。Java的输入输出是以流的形式来完成的。InputStreamReader的对象reader从系统输入中读取输入流,保存在相应的缓冲区中,因此第2个空的答案是System.in。BufferedReader对象则是从这个缓冲区中读取数据,使用BufferedReader类的readLine()方法即可获得输入流中的一行输入。在Java程序中,文件作为类的一个实例来处理,File类具有很多与文件相关的方法,比如获得上级目录名(getParent()方法)、路径(getPath()方法)等,第3个空就是使用getName()方法获取文件的文件名。

  • 第2题:

    下列程序的运行结果是______。 package ch1; import java.io. *; public class ex28 { public static void main (String args [] ) throws IOException { try { File f1 = new File("ch1\\dir28"); f1.mkdir(); File f2 = new File(f1, "file59.txt"); FileOutputStream fos = new FileOutputStream(f2); for(int i = 0; i < 2; i++) { String s= i + "times"; byte[] b = s.getBytes(); fos.write(b,0,b.length); } } catch(IOException ioe) { ioe.printStackTrace(); } } }

    A.在目录ch1下建立一个目录dir28,并且建立文件file28.txt,在文件中写入"Otimes 1 times"

    B.在目录ch1下建立一个目录dir28,并且建立文件file28.txt,在文件中写入“l times”

    C.在目录chi下建立一个目录dir28,并且建立文件file28.txt,在文件中写入“Otimes”

    D.抛出IOExceptin异常


    正确答案:A

  • 第3题:

    在J2EE中,加入在当前目录下不存在employee.txt文件。在当前目录下的一个类文件的 main函数只包含如下代码:  try{                //1    PrintWriter out=new PrintWriter(new FileOutputStream(“employee.txt”));//2    String name=”jb-aptech”;          //3    double salary=75000;           //4    out.print(name);            //5    out.print(„  „);            //6    out,print(salary);            //7  }                //8  catch(Exception e) {            //9    System.out.println(“文件没有被发现!”);       //10  }                //11  在DOS控制台上编译并运行该类文件。下面描述正确的是()。 

    • A、使用java命令运行该类文件,将在控制台上打印:”文件没有发现!”;
    • B、运行结束后打开employee.txt,会发现该文件什么都没有
    • C、运行结束后打开employee.txt,会发现该文件中有这样的文本:”jb-aptech 75000”
    • D、在第7行后加上代码:out.close (),编译并运行后,打开打开employee.txt,才会发现该文件中有这样的文本:”jb-aptech 75000.0”

    正确答案:B,D

  • 第4题:

    在J2EE中,Servlet1的代码如下:  import javax.servlet.*;  import javax.servlet.http.*; import java.io.*;  public class Servlet1 extends HttpServlet {  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {      response.setContentType("text/html");      PrintWriter out = response.getWriter();      String aa=request.getQueryString();      String bb=request.getMethod();      out.println(aa);  out.println(bb);   } }  把Servlet1.class文件放在Web服务器适合的目录下,在浏览B器地址栏内输入:http://localhost:8080/servlet/Servlet1?name=jb-aptech&phone=12345678,看到的结果是()。 

    • A、name=jb-aptech&phone=12345678 GET
    • B、name=jb-aptech,phone=12345678 GET
    • C、jb-aptech,12345678 POST
    • D、name,phone GET
    • E、2,POST

    正确答案:A

  • 第5题:

    在J2EE中,如果去编译并运行下面的代码,在这里假定在当前目录下没有Hello.txt文件: import java.io.*;  public class Mine {  public static void main(String argv[]){      Mine m=new Mine();  System.out.println(m.amethod());   }  public int amethod() {     try {  FileInputStream dis=new FileInputStream("Hello.txt");  }  catch (FileNotFoundException fne) {  System.out.println("No such file found");          return -1;     }  catch(IOException ioe)  { }     finally {  System.out.println("Doing finally");     }  return 0;   } }  结果会输出()。 

    • A、No such file found
    • B、No such file found -1
    • C、No such file found doing finally -1
    • D、0

    正确答案:C

  • 第6题:

    //point X  public class foo { public static void main (String[]args) throws Exception {  java.io.printWriter out = new java.io.PrintWriter {  new java.io.outputStreamWriter (System.out), true;  out.printIn(“Hello”); }  }  }   Which statement at PointX on line 1 allows this code to compile and run?()  

    • A、 Import java.io.*;
    • B、 Include java.io.*;
    • C、 Import java.io.PrintWriter;
    • D、 Include java.io.PrintWriter;
    • E、 No statement is needed.

    正确答案:E

  • 第7题:

    //point X    public class foo (   public static void main (Stringargs) throws Exception {   printWriter out = new PrintWriter (new )  java.io.outputStreamWriter (System.out), true;   out.printIn(“Hello”);    }   )   Which statement at PointX on line 1 allows this code to compile and run?()

    • A、 Import java.io.PrintWriter;
    • B、 Include java.io.PrintWriter;
    • C、 Import java.io.OutputStreamWriter;
    • D、 Include java.io.OutputStreamWriter;
    • E、 No statement is needed.

    正确答案:A

  • 第8题:

    多选题
    在J2EE中,加入在当前目录下不存在employee.txt文件。在当前目录下的一个类文件的 main函数只包含如下代码:  try{                //1    PrintWriter out=new PrintWriter(new FileOutputStream(“employee.txt”));//2    String name=”jb-aptech”;          //3    double salary=75000;           //4    out.print(name);            //5    out.print(„  „);            //6    out,print(salary);            //7  }                //8  catch(Exception e) {            //9    System.out.println(“文件没有被发现!”);       //10  }                //11  在DOS控制台上编译并运行该类文件。下面描述正确的是()。
    A

    使用java命令运行该类文件,将在控制台上打印:”文件没有发现!”;

    B

    运行结束后打开employee.txt,会发现该文件什么都没有

    C

    运行结束后打开employee.txt,会发现该文件中有这样的文本:”jb-aptech 75000”

    D

    在第7行后加上代码:out.close (),编译并运行后,打开打开employee.txt,才会发现该文件中有这样的文本:”jb-aptech 75000.0”


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

  • 第9题:

    单选题
    在J2EE中,Servlet1的代码如下:  import javax.servlet.*;  import javax.servlet.http.*; import java.io.*;  public class Servlet1 extends HttpServlet {  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {      response.setContentType("text/html");      PrintWriter out = response.getWriter();      String aa=request.getQueryString();      String bb=request.getMethod();      out.println(aa);  out.println(bb);   } }  把Servlet1.class文件放在Web服务器适合的目录下,在浏览B器地址栏内输入:http://localhost:8080/servlet/Servlet1?name=jb-aptech&phone=12345678,看到的结果是()。
    A

    name=jb-aptech&phone=12345678 GET

    B

    name=jb-aptech,phone=12345678 GET

    C

    jb-aptech,12345678 POST

    D

    name,phone GET

    E

    2,POST


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

  • 第10题:

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

  • 第11题:

    单选题
    //point X  public class foo { public static void main (String[]args) throws Exception {  java.io.printWriter out = new java.io.PrintWriter {  new java.io.outputStreamWriter (System.out), true;  out.printIn(“Hello”); }  }  }   Which statement at PointX on line 1 allows this code to compile and run?()
    A

     Import java.io.*;

    B

     Include java.io.*;

    C

     Import java.io.PrintWriter;

    D

     Include java.io.PrintWriter;

    E

     No statement is needed.


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

  • 第12题:

    单选题
    在J2EE中,如果去编译并运行下面的代码,在这里假定在当前目录下没有Hello.txt文件: import java.io.*;  public class Mine {  public static void main(String argv[]){      Mine m=new Mine();  System.out.println(m.amethod());   }  public int amethod() {     try {  FileInputStream dis=new FileInputStream("Hello.txt");  }  catch (FileNotFoundException fne) {  System.out.println("No such file found");          return -1;     }  catch(IOException ioe)  { }     finally {  System.out.println("Doing finally");     }  return 0;   } }  结果会输出()。
    A

    No such file found

    B

    No such file found -1

    C

    No such file found doing finally -1

    D

    0


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

  • 第13题:

    下列程序执行后的结果是______。 package ch1; import java.io.*; public class ex22 { static, String filename = "ch1\kfile22.txt"; public static void main(String[] args) { try { FileWriter fr = new FileWriter(filename); PrintWriter pr = new PrintWriter(fr); String name = "xiaoming"; String phone = "123456"; String age = "12"; pr.println(name + ',' + phone + ',' + age); pr.close(); fr.close(); } catch(IOException ioe) { ioe.printStackTrace() } } }

    A.在包ch1 中新建一个文件file22.txt, 并且在其中写入一行字符串“xiaomingl2345612”

    B.在包ch1中新建一个文件file22.txt,并且在其中写入一行字符串“xiaoming, 123456,12”

    C.在包chi中新建一个文件file22.txt,并且在其中写入一行字符串“xiaoming'’

    D.抛出IOException


    正确答案:B

  • 第14题:

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

  • 第15题:

    在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

  • 第16题:

    //point X  public class foo (  public static void main (String[]args) throws Exception {  printWriter out = new PrintWriter (new  java.io.outputStreamWriter (System.out), true;  out.printIn(“Hello”);  }  )   Which statement at PointX on line 1 allows this code to compile and run?()  

    • A、 Import java.io.PrintWriter;
    • B、 Include java.io.PrintWriter;
    • C、 Import java.io.OutputStreamWriter;
    • D、 Include java.io.OutputStreamWriter;
    • E、 No statement is needed.

    正确答案:A

  • 第17题:

    在J2EE中,假如在当前目录下不存在employee.txt文件。在当前目录下的一个类文 件的main函数只包含如下代码: try{                //1   PrintWriter out =new  PrintWriter(new FileOutputStream(“employee.txt”));  //2    String name = “jb-aptech”;           //3    double salary = 75000;            //4    out.print(name);             //5    out.print(“ ”);             //6    out.println(salary);             //7  }                //8   catch(Exception e)  {           //9   System.out.println(“文件没有发现!”);         //10  }                 //11  在DOS控制台上编译并且运行该类文件。下面的描述正确的是()。 

    • A、使用java命令运行该类文件,将在控制台上打印:”文件没有发现!”
    • B、运行结束后打开employee.txt,会发现该类文件什么也没有
    • C、运行结束打开employee.txt,会发现文件中有这样的文本:“jb-aptech 75000”
    • D、在第7行后加上:out.close(),编译并运行该文件后,打开employee.txt,会发现文件中有这样的文本:“jb-aptech 75000.0”
    • E、把第2行代码改为:PrintWriter out = PrintWriter(new File

    正确答案:B,D

  • 第18题:

    //point X   public class foo {  public static void main (Stringargs) throws Exception {   java.io.printWriter out = new java.io.PrintWriter {   new java.io.outputStreamWriter (System.out), true;   out.printIn(“Hello”);   }   } }   Which statement at PointX on line 1 allows this code to compile and run?()  

    • A、 Import java.io.*;
    • B、 Include java.io.*;
    • C、 Import java.io.PrintWriter;
    • D、 Include java.io.PrintWriter;
    • E、 No statement is needed.

    正确答案:E

  • 第19题:

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


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

  • 第20题:

    多选题
    在J2EE中,假如在当前目录下不存在employee.txt文件。在当前目录下的一个类文件的main函数只包含如下代码:  try {                                                             PrintWriter out = new PrintWriter(new FileOutputStream(“employee.txt”));      String name = “jb-aptech”;                                    double salary = 75000;                                            out.print(name);                                                out.print(„ „);                                                out.println(salary);                                        }                                                              catch(Exception e)                                               System.out.println("文件没有发现!");                                                        在DOS控制台上编译并且运行该类文件。下面的描述正确的是()。
    A

    使用java命令运行该类文件,将在控制台上打印:文件没有发现!

    B

    运行结束后打开employee.txt,会发现该文件什么也没有

    C

    运行结束后打开employee.txt,会发现文件中有这样的文本:“jb-aptech 75000”

    D

    在第7行后加上代码:out.close(),编译并运行该类文件后,打开employee.txt,才会发现文件中有这样的文本:“jb-aptech 75000.0”

    E

    把第2行代码改为: PrintWriter out = new PrintWriter(new FileOutputStream(“employee.txt”),true);  编译并运行该类文件后,打开employee.txt,才会发现文件中有这样的文本:“jb-aptech 75000.0”


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

  • 第21题:

    多选题
    在J2EE中,假如在当前目录下不存在employee.txt文件。在当前目录下的一个类文 件的main函数只包含如下代码: try{                //1   PrintWriter out =new  PrintWriter(new FileOutputStream(“employee.txt”));  //2    String name = “jb-aptech”;           //3    double salary = 75000;            //4    out.print(name);             //5    out.print(“ ”);             //6    out.println(salary);             //7  }                //8   catch(Exception e)  {           //9   System.out.println(“文件没有发现!”);         //10  }                 //11  在DOS控制台上编译并且运行该类文件。下面的描述正确的是()。
    A

    使用java命令运行该类文件,将在控制台上打印:”文件没有发现!”

    B

    运行结束后打开employee.txt,会发现该类文件什么也没有

    C

    运行结束打开employee.txt,会发现文件中有这样的文本:“jb-aptech 75000”

    D

    在第7行后加上:out.close(),编译并运行该文件后,打开employee.txt,会发现文件中有这样的文本:“jb-aptech 75000.0”

    E

    把第2行代码改为:PrintWriter out = PrintWriter(new File


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

  • 第22题:

    单选题
    //point X   public class foo {  public static void main (Stringargs) throws Exception {   java.io.printWriter out = new java.io.PrintWriter {   new java.io.outputStreamWriter (System.out), true;   out.printIn(“Hello”);   }   } }   Which statement at PointX on line 1 allows this code to compile and run?()
    A

     Import java.io.*;

    B

     Include java.io.*;

    C

     Import java.io.PrintWriter;

    D

     Include java.io.PrintWriter;

    E

     No statement is needed.


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

  • 第23题:

    多选题
    在J2EE中,假如在当前目录下不存在employee.txt文件。在当前目录下的一个类文件的main函数只包含如下代码: try{//1 PrintWriterout=newPrintWriter(newFileOutputStream(“employee.txt”));//2 Stringname=“jb-aptech”;//3 doublesalary=75000;//4 out.print(name);//5 out.print(‘‘);//6 out.println(salary);//7 }//8 catch(Exceptione)//9 System.out.println("文件没有发现!");//10 在DOS控制台上编译并且运行该类文件。下面的描述正确的是()。
    A

    使用java命令运行该类文件,将在控制台上打印:文件没有发现!

    B

    运行结束后打开employee.txt,会发现该文件什么也没有

    C

    运行结束后打开employee.txt,会发现文件中有这样的文本:“jb-aptech75000”

    D

    在第7行后加上代码:out.close(),编译并运行该类文件后,打开employee.txt,才会发现文件中有这样的文本:“jb-aptech75000.0”

    E

    把第2行代码改为:PrintWriterout=newPrintWriter(newFileOutputStream(“employee.txt”),true);编译并运行该类文件后,打开employee.txt,才会发现文件中有这样的文本:“jb-aptech75000.0”


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