Java程序设计实习指导书_实验五

2019-01-10 11:00

实验五 Java 输入输出流

1.实验目的

(1) 掌握输入输出流的总体结构; (2) 掌握流的概念;

(3) 了解各种流(包括文件流、数组流、数据流、对象的序列化、随机访问)的使用。

2.实验内容

实验题1 阅读下面程序,叙述其功能 package cn.edu.nwsuaf.jp; import java.io.FileReader; import java.io.IOException; public class FileViewer {

/** Defines the entry point of the program. */ public static void main(String[] args) {

System.out.println(\try {

// Reads the file name from the System.in stream. String fileName = \while(true) { }

// Reads the file and prints it to the System.out stream. char[] buffer = new char[20];

- 1 -

int readByte = System.in.read(); if(readByte == -1 || readByte == '\\r')

break;

fileName += (char) readByte;

}

}

FileReader reader = new FileReader(fileName); while(true) { }

int length = reader.read(buffer);

if(length < 0) // Reads a long as there is more data.

break;

String text = new String(buffer, 0, length); System.out.print(text);

} catch (IOException e) { }

e.printStackTrace();

[基本要求] 写出本题程序的功能。

实验题2 设计一个类FileRWTest,实现从input.txt文件中读入数据到字符数组cBuffer中,然后再写入到文件“output.txt”中。

[基本要求] 编写完整程序。

实验题 3 \水仙花数\。所谓\水仙花数\是指一个3位数,其各位数字立方和等于

该数本身。例如,153就是一水仙花数,因为153 = 13+53+33 。

请计算出100万以内所有的水仙花数,并以一行一个水仙花数的格式保存到文本文件data.txt中。输出格式如下:

153 = 1*1*1 + 5*5*5 + 3*3*3

实验题 4 P312 习题9.

- 2 -


Java程序设计实习指导书_实验五.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:房地产现场项目部管理制度及职责(最新实用版)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: