JAVA I/O - PowerPoint PPT Presentation

About This Presentation
Title:

JAVA I/O

Description:

JAVA I/O OUTLINE I/O streams Byte Streams Character Streams Buffered Stream I/O from the Command Line Standard I/O java.io.Console File I/O File I/O Data Streams ... – PowerPoint PPT presentation

Number of Views:58
Avg rating:3.0/5.0
Slides: 30
Provided by: May131
Category:

less

Transcript and Presenter's Notes

Title: JAVA I/O


1
JAVA I/O
2
OUTLINE
  • I/O streams
  • Byte Streams
  • Character Streams
  • Buffered Stream
  • I/O from the Command Line
  • Standard I/O
  • java.io.Console
  • File I/O
  • File I/O
  • Data Streams
  • Object Streams

3
I/O STREAMS
  • ??????0?1???????
  • ?source??input stream ????
  • ????output stream ?????

source
read
program
0101
destination
write
program
0101
4
BYTE STREAMS
  • ?????
  • Input?output????????????(8-bits)
  • Ex. System.in, FileInputStream/FileOutputStream

5
Java.io.
FileInputStream
InputStream
FilterInputStream
BufferedInputStream
FileOutputStream
OutputStream
BufferedOutputStream
FilterOutputStream
6
SYSTEM.IN
  • ????8 bits
  • Output????ASCII code(A65)

7
FILEINPUTSTREAM/FILEOUTPUTSTREAM
  • FileInputStream?????bytes
  • FileOutputStream ?bytes??????
  • ????????????java.io.FileNotFoundException

8
FILEINPUTSTREAM/FILEOUTPUTSTREAM
9
FILEINPUTSTREAM/FILEOUTPUTSTREAM
InputStream
t
e
s
t
f
o
r
b
y
t
e
s
t
r
e
a
m
read()
int c (b 98)
write(c)
t
e
s
t
f
o
r
b
OutputStream
10
CHARACTER STREAMS
  • ????
  • ????(Unicode)??????????????????character stream,
    ????2 bytes
  • Ex. FileReader/FileWriter

11
Java.io.
BufferedReader
Reader
FileReader
InputStreamReader
BufferedWriter
Writer
FileWriter
OutputStreamWriter
12
FILEREADER/FILEWRITER
13
FILEREADER/FILEWRITER
  • FileReader?character stream,????????,???FileInputS
    tream(?byte stream)????????????????

14
BUFFERED STREAM
  • ????
  • ???????????, Buffered Stream?????????????,????????
    ?,????????????,?????????????,?????????

read
file
memory
program
0101
write
file
program
memory
0101
15
BUFFERED STREAM
  • BufferedInputStream, BufferedOutputStream?byte
    stream?????
  • BufferedReader, BufferedWriter??character
    stream?????

16
BUFFERED STREAM
17
I/O FROM THE COMMAND LINE
  • ???????,???????

read
program
0101
18
STANDARD I/O
  • Standard input System.in
  • Standard output System.out
  • Standard error System.err

19
STANDARD I/O
  • ??????BufferedReader bf new BufferedReader(new
    InputStreamReader(System.in))
  • new InputStreamReader(System.in)??System.in???????
    ?????????
  • ??buffered stream?????buffer?,?????????????????
    bf.readLine(),????

20
STANDARD I/O
21
JAVA.IO.CONSOLE
  • JAVA JDK6???
  • ??System?console()??,??????Console??(Console
    ???????????,?? Windows ????????),?????????????????
    ?????
  • ?standard I/O????

22
JAVA.IO.CONSOLE
????????????,????????????
23
FILE I/O
  • ?????????????????

read
File
program
0101
24
FILE I/O
  • ????

25
DATAINPUTSTREAM/DATAOUTPUTSTREAM
  • DataInputStream reads bytes from the stream and
    converts them into appropriate primitive type
    values or strings.
  • DataOutputStream converts primitive type values
    or strings into bytes and outputs the bytes to
    the stream.

26
DATAINPUTSTREAM/DATAOUTPUTSTREAM
DataInputStream
DataOutputStream
readBoolean() readByte() readChar() readFloat() re
adInt()
writeBoolean() writeByte() writeChar() writeFloat(
) writeInt()
27
DATAINPUTSTREAM/DATAOUTPUTSTREAM


28
OBJECTSTREAM
  • ????
  • ObjectOutputStream????????????,????????ObjectInput
    Stream???????????

29
OBJECTSTREAM
Write a Comment
User Comments (0)
About PowerShow.com