实验五 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 -
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库Java程序设计实习指导书_实验五在线全文阅读。
相关推荐: