Java experiment 8-java input/output stream

Source: Internet
Author: User

1 Read and write files

"Experimental Purpose"

(1) Master the reading and writing method of the text file.

(2) Master the method of reading and writing random files.

(3) Master the basic use of InputStreamandoutputstream abstract class.

(4) Mastering fileinputstream,fileoutputstream,datainputstream, DataOutputStream The basic use of abstract classes.

"Experimental Requirements"

Requirements One: Establish the Streamdemo class, to achieve the establishment of a standard input and output stream, can read the string from the keyboard and output the string.

Requirement Two: Apply Java input and output stream, processing a picture file: Write a few characters " by Michael" On the picture, add the name to the picture to identify "I process the picture", then, Place the picture on the panel and place the panel in the frame.


Requirement Two:

Method 1

Create a JFrame a JPanel a jlabel through the ImageIO read a picture put the picture into JLabel JLabel put in JPanel JPanel in JFrame

write characters on a picture with a graphics

Import Java.awt.color;import java.awt.graphics;import Java.awt.image.bufferedimage;import Java.io.File;import Java.io.ioexception;import javax.swing.*;import javax.imageio.*;p ublic class Demo {/** * @param args * @throws exception< C0/>*/public static void Main (string[] args) throws Exception {//TODO auto-generated method stubbufferedimage image = Ima Geio.read (New File ("f:\\fd.jpg")); Graphics g = Image.getgraphics (); G.setcolor (color.red); G.drawchars ("by Michael". ToCharArray (), 0, 10, 10, 10); G.setcolor (Color.green); G.drawchars ("I Process the picture". ToCharArray (), 0, "I process the picture". Length (), Image.getwidth ()-80, Image.getheight ()-10); JFrame JM = new JFrame (); Jm.setbounds (n, A, A, a), ImageIcon IC = new ImageIcon (); JPanel panel = new JPanel (); JLabel JL = new JLabel (new ImageIcon (image));p Anel.add (JL); Jm.getcontentpane (). Add (Panel); jm.setvisible (True);}}


Java experiment 8-java input/output stream

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.