Java Lab 3: Stream Handler Design

Source: Internet
Author: User
Tags string to file


Topic 3: Stream processing program Design


Experimental purposes and requirements: Students are required to learn and understand the Java Stream programming theory on the basis of learning and understanding of the classroom learning content, learning and gradually master the programming and debugging of the stream program, to learn the correct choice of different streams according to the processing requirements of the use and combination of methods.


Experimental content:

Design and write a program to read a line of string from the keyboard, write it into a text file,

Then write another program to read the string from the text file and display it in the command-line window.


Program 1:

Reads a line of string from the keyboard, writes it into a text file

Import Java.io.*;import java.util.*;p Ublic class in {public static void main (String args[]) {    Scanner input=new Scanne R (system.in);    try{    System.out.println ("Please enter:");      String Str=input.nextline ();//read in line string    FileWriter output = new FileWriter ("In.txt");    BufferedWriter outtwo = new BufferedWriter (output);//File Buffered stream    outtwo.write (str);//write String to file    Outtwo.newline () ;//Fetch another row    }    catch (IOException e) {    System.out.println (e);    }}}

Program 2:

Reads a string from a text file and displays it in a command-line window.

Import Java.io.*;import java.util.*;p Ublic class out {public static void main (String args[]) {try{string str=null;     FileReader input=new FileReader ("In.txt");     BufferedReader intwo=new BufferedReader (input);//build file read buffer stream while     ((Str=intwo.readline ())!=null) {//Read into end of file     System.out.println (str);//Output     }     }     catch (IOException e) {}}}


Java Lab 3: Stream Handler Design

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.