File类提供了一系列方法,用于操作其内部封装的路径指向的文件或者目录,当File对象对应的文件不存在时,使用哪个方法将新建的一个File对象指定到新文件中。()
A. String getAbsolutePath()
B. boolean canRead()
C. boolean createNewFile()
D. boolean exists()
查看答案
用“new FileOutputStream("data.txt",true)”创建一个FileOutputStream对象,则下面说法哪个错误的? ()
A. 如果文件data.txt不存在,也不一定会抛出IOException异常
B. 如果文件data.txt不存在,则可能会新建文件data.txt
C. 如果文件data.txt存在,则将覆盖掉文件中原有的内容
D. 如果文件data.txt存在,则从文件的末尾开始添加新内容
下列选项中,那些事标准输入输出流?()(多选)
A. System.In
B. System.Out
C. InputStream
D. OutputStream
文件E.java的长度是51个字节,请说出E类中标注的【代码1】,【代码2】的输出结果。import java.io.*;public class E {public static void main(String args[]) {File f = new File("E.java");try{ RandomAccessFile in = new RandomAccessFile(f,"rw");System.out.println(f.length()); //【代码1】FileOutputStream out = new FileOutputStream(f);System.out.println(f.length()); //【代码2】} catch(IOException e) {System.out.println("File read Error"+e);}}}
请说出E类中标注的【代码1】~【代码4】的输出结果。import java.io.*;public class E {public static void main(String args[]) {int n=-1;File f =new File("hello.txt");byte [] a="abcd".getBytes();try{ FileOutputStream out=new FileOutputStream(f);out.write(a);out.close();FileInputStream in=new FileInputStream(f);byte [] tom= new byte[3];int m = in.read(tom,0,3);System.out.println(m);//【代码1】String s=new String(tom,0,3);System.out.println(s);//【代码2】m = in.read(tom,0,3);System.out.println(m);//【代码3】s=new String(tom,0,3);System.out.println(s);//【代码4】}catch(IOException e) {}}}