South Mail Java programming Experiment 3 Stream processing program design
Experimental Purpose:
The students are required to learn and understand the Java stream programming theory based on the learning and understanding of the classroom learning content, and learn how to use and combine the correct selection of different streams according to the processing requirements.
Experimental content:
Design and write a program that reads a line of string from the keyboard, writes it to a text file, and then writes another program to read the string from a text file and display it in a command-line window.
Lab Procedure 1:
Reads a line with the basic read-in scanner of the data and writes the file with a buffered stream.
Import Java.io.*;import java.util.*;p ublic class Javaout {public static void Main (String args[]) { Scanner input = new Scanner (system.in); Read Stream System.out.println ("Please enter a line string:"); String str = input.nextline (); Reads a whole line of string file File = new file ("Test.txt"); Create file try{ FileWriter output = new FileWriter (file, true); BufferedWriter OutB = new BufferedWriter (output); File buffer stream outb.write (str); The file is written to the string outb.newline (); NewLine outb.close (); Close file outb.close (); } catch (IOException e) { System.out.println (e);}} }
Lab Procedure 2:
Read into the file with a buffered stream, and the basic output outputs the entire line.
Import Java.io.*;import java.util.*;p ublic class Javain {public static void Main (String args[]) { try{ FileReader input = new FileReader ("Test2.txt"); BufferedReader InB = new BufferedReader (input); File read-in Buffer stream creation String s = ""; while ((s = inb.readline ()) = null) {//entire line read in, until end of file System.out.println (s); } Inb.close (); Input.close (); } catch (IOException e) { System.out.println (e);}} }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
South Mail Java programming Experiment 3 Stream processing program design