班级:13 科技 2 班 学号:5 :许耿宁 Java 多线程和输入输出流一、实验目的:1.熟悉利用 Thread 类建立多线程方法。2.熟悉利用 Thread 接口建立多线程方法。3.熟悉 Java 的文件读写机制,练习输入输出流的使用。二、实验容: 1.阅读下列程序,分析并上机检验其功能。public class DelayRunnable implements Runnable{private static int count=0;private int no;private int delay;public DelayRunnable(){ count++; no=count; } public void run(){ try{ for (int i=0;i<10;i++){ delay=(int)(Math.random()*5000); Thread.sleep(delay); System.out.println("Thread "+no+" with a delay "+delay); } }catch(InterruptedException e){}}}class MyRunnable{public static void main(String args[]){DelayRunnable r1 = new DelayRunnable();DelayRunnable r2 = new DelayRunnable();Thread thread1=new Thread(r1);Thread thread2=new Thread(r2);thread1.start();thread2.start();try{Thread.sleep(1000);}catch(InterruptedException e){System.out.println("Thread wrong");}}}2.将上列程序利用 Runnable 接口改写,并上机检验。3.创建简单的程序 ThreeThread.java,该程序将创建三个线程,每个线程应当显示它所运行的时间(可以考虑使用 Date 类或 Calendar 类)。4.键盘输入 10 个整数,从小到大进行排序。5.接收键盘输入的字符串,用 FileInputStream 类将字符串写入文件,用FileOutputStream 类读出文件容显示在屏幕上。6.将一个文本文件的容按行读出,每读出一行就顺序加上行号,并写入到另一个文件中。三、实验要求:1.通过实验掌握 Thread 、Runnable 使用方法;2.程序必须能够实现多线程;3.程序必须能够完成题目要求;4.通过实验掌握文件输入输出流的使用方法;5.程序必须能够从键盘接收字符串并保存在文件中;6.程序必须能够读出文件容显示在屏幕上;7.写出实验报告。四、实验代码与截图:第一题:在编译器上运行程序得到截图所示结果:第二题:① 实验代码public class DelayThread extends Thread{ private static int count=0; private int no; private int delay; public DelayThread(){ count++; no=count; }public void run(){ try{ for (int i=0;i<10;i++){ delay=(int)(Math.random()*5000); sleep(delay);...