- 1、本文档共7页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
实验五Java输入输出流.doc
实验五Java输入输出流
实验目的
掌握输入输出流的总体结构;
掌握流的概念;
了解齐种流(包括文件流、管道流、连接文件、过滤流、对象的序列化、 随机访问)的使用。
实验内容
实验题1编写一个Java Application程序,打卬命令彳亍输入的所有参数。 [基本要求]编写完整程序。
import java.util.Scanner;
public class xinxi {
public static void main(StringlJ args) {
String name;
String Sage;
int age;
String Ssore;
double sore;
Scanner in = new Scanner(System.in);
System.out.println(M请输入你的姓名:”);
name = in.nextLine();
System.out.println(请输入您的年龄:”);
Sage = in.nextLine();
age = Integer.parselnt(Sage);
System, out. pri nt ln(请输入您的分数”);
Ssore =in.nextLine();
sore = Double, par seDou ble(S sore);
System.out.println(name+n H+age+H n+sore);
Problems @ Javadoc Declaration § Console
erminated xinxi [Java Application] C:\Program Files\Genuitec 请输入你的姓名:
niuiqn
请输入您的年龄:
21
请输入您的分数
100
niuiqn 21 100.0
实验题2阅读卜而程序,叙述其功能
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[J args) {
System.out.println(HPlease enter the file path:”);
try {
String fileName =
while(true) {
int readByte = System.inread();
if(readByte == -1 II readByte == V)
break;
fileName += (char) readByte;
}
// Reads the tile and prints it to the System.out stream.
char [J buffer = new char[20J;
FileReader reader = new FileReader(fileName);
while(true) {
int length = reade匚read(buffer);
if(length 0) // Reads a long as there is more data.
break;
String text = new String(buffer, 0, length);
System, out. pri nt(text);
}
} catch (IOException e) {
e.pri ntStackT race();
}
}
}
[基木要求]写出木题程序的功能。
程序的功能是:在控制台输入绝对路径,并打开绝对路径下的内容。
实验题3设计一个类FileRWTest,实现从input.txt文件屮读入数据到字符数组 eBuffer中,然后再写入到文件“output.txt中。
[基本要求]编写完整程序。
import java.io. *;
public class FileRWTest {
public static void main(String[] args) throws FileNotFoundException
{
int rs;
File file = new File(nD:\\haon,HInput.txtH);
File fileout = new File(,D:\\hao,Output.txtn);
FilelnputStream fis = new FilelnputStream(file);
FileOutputStream fos = new FileOutputStream(fileout,true)
文档评论(0)