二者的构造函数
read()
close()
write()
第1题:
下面关于java中输入/输出流的说法正确的是()。
A.FileInputStream与FileOutputStream类用读、写字节流
B.Reader与Writer类用来读、写字符流
C.RandomAccessFile既可以用来读文件,也可以用来写文件
D.File类用来处理与文件相关的操作
第2题:
下列程序要求将source.txt文件中的字符,通过文件输入/输出流复制到另一个dest.txt文件中。请将程序补充完整。
注意:不改动程序结构,不得增行或删行。
import java.io.*;
public class ex2
{
public static void main(String[] args) throws IOException
{
File inputFile;
File outputFile;
FileInputStream in;
FileOutputStream out;
int c;
inputFile=new File("source.txt");
utputFile=new File("dest.txt");
in=new FileInputStream(inputFile);
______(outputFile);
while((c=in.read())!=-1)
______;
in.close();
out.close();
}
}
第3题:
A.IOException
B.IOException!Exception!
C.FileNotFundException!IOException!
D.FileNotFundException!IOException!Exception!
第4题:
用“newFileOutputStream(“data.txt”,true)”创建一个FileOutputStream实例对象,则下面( )说法是正确的。
A、如果文件“data.txt”存在,则将抛出IOException异常
B、如果文件“data.txt”存在,则将在文件的末尾开始添加新内容
C、如果文件“data.txt”存在,则将覆盖掉文件中已有的内容
D、如果文件“data.txt”不存在,则将抛出IOException异常
第5题:
阅读下面写文件的程序 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
第6题:
Java中,类FileInputStream和FileOutputStream提供了对文件的读/写方法是
A.跳跃
B.顺序
C.随机或顺序
D.随机
第7题:
Java中处理压缩流的抽象类是
A.InputStream和OutputStream
B.Reader和Writer
C.InflaterInputStream和DeflaterOutputStream
D.FileInputStream和FileOutputStream
第8题:
请完成程序,首先由一个类simple实现Serializable接口,并有三个成员变量,分别为int型、double型和String型,可以用toString的方法显示这三个成员变量。在main方法中创建这个simple的持久对象,根据用户在命令行输入的三个参数来设定其中成员变量的值。然后,将这个对象写入名为TheSerial.data的文件中,并显示成员变量。最后从文件TheSerial.data中读出三个成员变量并显示出来。
注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。
import java.io.*;
class TheSerial implements Serializable
{
private int intvalue;
private double doublevalue;
private String string;
The Serial ()
{
intvalue=123;
doublevalue=12.34;
string="Serialize Test";
}
public void setDouble(double d)
{
doublevalue=d;
}
public void setInt(int i)
{
intvalue=i;
}
public void setString(String s)
{
string=s;
}
public String to String()
{
return("int="+intvalue+" double="+doublevalue+" string="+string);
}
}
public class simple
{
public static void main(String[] args)
{
The Serial e1=new TheSerial();
TheSerial e2;
try
{
e1.setInt(Integer.parseInt(args[0]));
e1.setDouble(Double.parseDouble(args[1]));
e1.setString(args[2]);
}
catch(Exception e)
{
e1.setString(e.getMessage());
}
System.out.println(e1);
try
{
FileOutputStream S=new FileOutputStream("TheSerial.data");
ObjectOutputStream OS=new ObjectOutputStream(oS);
______;
}
catch(IOException ioException)
{
System.out.println (ioException.getMessage ());
}
try
{
FileInputStream iS=new FileInputStream("TheSerial.data");
ObjectInputStream IS=new ObjectInputStream(iS);
______;
System.out.println(e2);
}
catch(IOException ioException)
{
System.out.println(ioException.getMessage());
}
catch(ClassNotFoundException cnfException)
{
System.out.println(cnfException.getMessage());
}
}
}
第9题:
A.File
B.FileOutput
C.OutputStream
D.InputStream
第10题:
下面的代码中方法unsafe()有异常发生,那么可以加在第一行的语句为( )。 { if(unsafe()) { //do something } else if(safe()) { //do the other) } Ⅰ:public void methodName() Ⅱ:public void methodName() throw IOException Ⅲ:public void methodName() throws IOException Ⅳ:public void methodName() throws Exception
A.Ⅲ、Ⅳ
B.Ⅱ、Ⅲ、Ⅳ
C.Ⅰ、Ⅲ
D.Ⅰ、Ⅳ