South Mail Java programming Experiment 3 Stream processing program design

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.