选择题
1. | 在使用FileInputStream流对象的read方法读取数据时可能会产生下列哪种类型的异常 A.ClassNotFoundException B.FileNotFoundException C.RuntimeException D.IOException |
---|
答案:D
2. | 在建立FileInputStream流对象时可能会产生下列哪种类型的异常 A.ClassNotFoundException B.FileNotFoundException C.RuntimeException D.AWTException |
---|
答案:B
3. | 下列选项中能独立完成外部文件数据读取操作的流类是 A.InputStream B.FileInputStream C.FilterInputStream D.DataInputStream |
---|
答案 :B
4. | 以下选项中哪个类是所有输入字节流的基类 B. OutputStream C. Reader D. Writer |
---|
答案:A
5. | 以下选项中属于字节流的是 B. FileWriter C. FileReader D.PrintWriter |
---|
答案:A
编程题
1. 文件复制
【问题描述】编写一个程序,实现文件的复制。程序的任务是将当前目录下filecopy.in文件复制成filecopy.out。
【输入文件】输入文件为当前目录下的filecopy.in。其内容由任意文本构成。
【输出文件】输出文件为当前目录下的filecopy.out。
【样例输入】若输入filecopy.in文件内容如下:
hello world1!#
hello world2!#
hello world3!#
hello world4!#
【样例输出】输出文件filecopy.out内容为:
hello world1!#
hello world2!#
hello world3!#
hello world4!#
【评分标准】该题要求输出文件与输入文件内容一致。如果你的输出文件正确,则该测试点得满分,否则该测试点得分为0。
【样例说明】输入文件为当前目录下的filecopy.in,输出文件为当前目录下的filecopy.out。
【评分标准】该题要求实现文件的复制。如果你的程序计算的结果和标准答案一致,则该测试点得满分,否则该测试点得分为0。
代码如下:
import java.io.*;
public class Homework_1 {
public static void main(String[] args) throws Exception {
FileInputStream fi = new FileInputStream("filecopy.in");
FileOutputStream fo = new FileOutputStream("filecopy.out");
BufferedInputStream bfi = new BufferedInputStream(fi);
BufferedOutputStream bfo = new BufferedOutputStream(fo);
int count = -1;
while ((count = bfi.read()) != -1) {
bfo.write(count);
}
bfo.flush();
bfo.close();
bfi.close();
}
}
博主java萌新,有问题可评论区共同交流学习,欢迎大家交流awa