标准文案
实验四 Java 输入输出流
1.实验目的
(1) 掌握输入输出流的总体结构; (2) 掌握流的概念;
(3) 了解各种流(包括文件流、过滤流、对象的序列化、随机访问)的使用。
2.实验内容
实验题1 编写一个Java Application程序,打印命令行输入的所有参数。 [基本要求] 编写完整程序。 运行结果:
代码如下:
import java.util.Scanner;
public class CommandOutPut { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(\:\); Scanner in = new Scanner(System.in);
大全
标准文案
}
}
String str = in.nextLine();
System.out.println(\:\); System.out.println(str); in.close();
实验题2 通过键盘输入路径,搜索指定路径下的全部内容。 运行结果:
代码如下:
package cn.edu.output;
import java.io.File;
import java.io.FileInputStream; import java.io.IOException;
public class Output { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub String fileName = \; File file = new File(fileName); byte[] b=new byte[(int)file.length()]; FileInputStream out=new FileInputStream(file);
大全
标准文案
} }
out.read(b); out.close();
String s=new String(b);//将字节流转换为字符串 System.out.println(s);
实验题3设计一个类FileRWTest,实现从input.txt文件中读入数据到字符数组cBuffer中,然后再写入到文件“output.txt”中。
运行结果:
代码:
package cn.edu.fileRWTester;
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException;
public class FileRWTest { /** * @param args
大全
完整word版,实验04Java输入输出流报告材料



