您好,欢迎来到保捱科技网。
搜索
您的当前位置:首页输入输出及文件操作

输入输出及文件操作

来源:保捱科技网
一 选择题

1 计算机中的流是:( )

A 流动的字节 B 流动的对象

C 流动的文件 D 流动的数据缓冲区

2 当输入一个字节流时,要( )

A 实现DataInput接口 B 实现ObjectInput接口 C Serializable接口 D 继承Reader抽象类

3 当检索一个压缩文件时,首先要建立压缩文件输入流对象。该对象 ( ) A 以选中的压缩文件为参数 B 以FileInputStream对象为参数 C 以InputStreamReader为参数 D 以BufferedReader对象为参数

4 如要求读取文件中的中间一段内容,最方便的采用下列哪种流来操作?( ) A File stream B Piep stream C Random stream D Filter stream

5 为读取的内容进行处理后再输出,需要使用下列哪种流?( ) A File stream B Piep stream C Random stream D Filter stream

二 填空题

1 在java中,字符是作为 码来处理的,每个字符用2个字节表示。 2 RamdonAccessFile所实现的接口是 3 请完成下列语句中应填的内容: File pathname = new File(args[0]); String[ ] filename =

4 java对I/O访问还提供了同步处理机制,这就是 。 5 字符类输出流的各个类都是抽象类 的字类。

三 编程题

1 程序将扫描该网址文件中的URL链接语句的模式匹配串,最后打印出链接网址列表。请在下划线处,填上适当语句完成此程序。 import java.io.*; import.java.net.*;

import.java.util.regex.*; Public class HrefMath

Public static void main(String[ ] args) { try{

String urlString;

If(args.length>0)urlString = args[0]; Else urlString = http://java.sun.com;

InputStreamReader in = new InputStreamReader(new URL(urlString.openStream( )); StringBuffer input = new StringBuffer( _); int ch;

while((ch=in.read())!= -1)input.append((char)ch);

String patternString “])\\\\s*>”; Pattern pattern=pattern.compile(patternString,patten.CASE_INSENSITIVE); While(matcher.find( )) { Int start=matcher.stat( ); Int end=matcher.end( );

Stromg match = input.substring(start,end); System.out.println(match); } }

catch(IOException exception) { Exception.printlStackTace( ); }

catch (PatternSyntaxException exception) { Exception.printlSackTace( ); } } }

2 本程序的功能是将一个工资表.dat文件以字符流的方式写入读出。这里的.dat文件是一个带有分隔符记录的Unicode码。请在下划线处,填入适当语句完成此程序。 import java.io.*; import java.util.*;

public class DataFileTest {

public satic void main (String[] args) { Employee[ ] staff = new Employee[3];

Staff[0] = new Employee(“Carl Cracker”,75000,1987,12,15); Staff[1] = new Employee(“Harry Hacker”,50000,19,10,1); Staff[2] = new Employee(“Tony Tester”,40000,1990,3,15); try {

PrintWriter out =new printWriter(new FileWriter(“employy.dat”); writeData(staff,out); out.close( );

BufferedReader in= new BufferedReader(new FileReader(“employee.dat”)); Employee[ ] newStaff = readData(in); In.close( );

For(int i=0;iCatch(IOException exception) { exceptionprintlStackTrace( ); } }

Static void writeData(Employee[] e,printWriter out)throws IOException {

out.println(e.length); for(int i=0;iStatic Employee[] readData(BufferedReader in)throws IOEception { int n=Integer.parseInt(in.readLine( )); Employee[]e= new Empolyee[n]; for(int i=0; iE[i] = new Employee( ); } return e; } }

3 请编写用RandomAccessFile oureFile; String s=“information to Append \\ n mon!\\n\\”;

oureFile = new RandomAccessFile oureFile(“phone.nember.numbers”,“rw”);模式打开访问oureFile文件,并在

文件尾加s的addFile程序。

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- baoaiwan.cn 版权所有 赣ICP备2024042794号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务