您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 55Java第10章--1(IO流处理)
JavaJavapenggang@mail.hust.edu.cnI/OI/OI/O1I/O/JavaStreamDataStream,SourceDestinationSink1I/OInputStreamOutputStreamJavajava.io//java.langjava.io1I/OJDK1.1java.iobyte16UnicodeJDK1.1java.ioReaderWriter2UnicodeInputStreamReaderUnicodeOutputStreamWriterJDK1.1java.io——ObjectInputObjectOutput1I/O——4InputStreamOutputStreamReaderWriter4IOInputStreamByteArrayInputStreamFileInputStreamFilterInputStreamBufferedInputStreamDataInputStreamLineNumberInputStreamPushbackInputStreamObjectInputStreamPipedInputStreamSequenceInputStreamStringBufferInputStreamOutputStreamByteArrayOutputStreamFileOutputStreamFilterOutputStreamBufferedOutputStreamDataOutputStreamPrintStreamObjectOutputStreamPipedOutputStream1I/O——1I/O——ReaderBufferedReaderLineNumberReaderCharArrayReaderFilterReaderPushbackReaderInputStreamReaderFileReaderPipedReaderStringReaderWriterBufferedWriterCharArrayWriterFilterWriterOutputStreamWriterFileWriterPipedWriterStringWriterPrintWriter1I/O——I/OInputStreamOutputStreamFileFileDescriptorRandomAccessFilejava.io.DataInputjava.io.DataOutput2java.awt.FileDialogDataInputObjectInputDataOutputObjectOutputFileFilterFilenameFilterObjectInputValidationObjectStreamConstantsSerializableExternalizablejava.ioP510java.ioP5102——2——I/Ojava.ioFileInputStreamFileOutputStreamFileFileDescriptorFilenameFilterRandomAccessFile7.9P515:ListJava.java2——FileInputStream/FileOutputStreamFileInputStreamFileNotFoundExceptionFileOutputStream/IOException//2——FileInputStream/FileOutputStreamFileInputStream(Filef)fFileInputStream(Stringname)nameFileOutputStream(Filef)fFileOutputStream(Stringname)nameFileOutputStream(Stringname,booleanappend)nameFilestreamTest.java/FileFileDescriptorFileFilter&FilenameFilterFile.list(FilenameFilterfnf)File.listFiles(FileFilterff)FileDialog.setFilenameFilter(FilenameFilterfnf)FileInputStream&FileReaderFileOutputStream&FileWriterRandomAccessFile/——FileDescriptorFileInputStream&FileOutputStream&RandomAccessFileFileDescriptorgetFD()FileDescriptorFileInputStream(FileDescriptorfdObj)FileOutputStream(FileDescriptorfdObj)FileReader(FileDescriptorfd)FileWriter(FileDescriptorfd)FileInputStreamfin=newFileInputStream(“file.txt”);FileReaderfr=newFileReader(fin.getFD());/——RandomAccessFileFileInputStream/FileOutputStreamFileReader/FileWriter/RandomAccessFileobjectDataInputDataOutputreadXXX()writeXXX()ReadInt(),ReadLine(),WriteChar(),WriteDouble()intskipBytes(intn)length()longgetFilePointer()voidseek(longpos)posfile/——RandomAccessFileRandom_file.javaRandomAccessFile(Filefile,Stringmode)RandomAccessFile(Stringname,Stringmode)mode“r”.IOException“rw”.“rws”.“rwd”.2——java.ioFilterInputStreamFilterOutputStream///FilterInputStreamFilterOutputStreamInputStreamOutputStream/protectedFilterInputStream(InputStreamin);protectedFilterOutputStream(OutputStreamout);2——BufferedInputStreamBufferedOutputStreamI/O“”I/OI/O328912BufferedInputStream(InputStreamin[,intsize])BufferedOutputStream(OutputStreamout[,intsize])2——FileInputStreamin=newFileInputStream(“file1.txt”);FileOutputStreamout=newFileOutputStream(“file2.txt”);BufferedInputStreambin=newBufferedInputStream(in,256)BufferedOutputStreambout=newBufferedOutputStream(out,256);intlen;bytebArray[]=newbyte[256];len=bin.read(bArray);//len,bArrayfile1.txtfile2.txtÆÆ2——BufferedOutputStreamflush()publicstaticvoidcopy(InputStreamin,OutputStreamout)throwsIOException{out=newBufferedOutputStream(out,32);byte[]buf=newbyte[32];intlen=in.read(buf);while(len!=-1){out.write(buf,0,len);len=in.read(buf);//}out.flush();//32}2——DataInputDataOutputintfloatbooleanread(),readInt(),readByte()…write(),writeChar(),writeBoolean()…readLine()2——DataInputStreamDataOutputStreamDataInputDataOutputbooleanintlongdouble2——,FileInputStreamfis=newFileInputStream(file1.txt);FileOutputStreamfos=newFileOutputStream(file2.txt);DataInputStreamdis=newDataInputStream(fis);DataOutputStreamdos=newDataOutputStream(fos);DataStreamTest.java2——java.langSystem/System.inInputStream()System.outPrintStream()System.errPrintStream()main2——PersistenceSerialization2—JavaSerializableSerializableSerializable“”2——/()ObjectOutputStreamObjectInputStreamObjectOutputObjectInputwriteObject()readObject()Student.javaObjectser.javaObjectRecov.java2——readObject()WriteObject()2——ThreadtransienttransientP527transient2——java.ioPipedInputStreamPipedOutputStream/2——/1PipedInputStream(PipedOutputStreampos);PipedOutputStream(PipedInputStreampis);2connect()PipedInputStreamconnect(PipedOutputStreampos);PipedOutputStreamconnect(PipedInputStreampis);PipeStreamTest.java2——I/Ojava.ioByteArrayInputStreamByteArrayOutputStreamStringBufferInputStreamByteArrayInputStreamByteArrayOutputStream32write()toByteArray()size()reset()StringBufferInputStreamByteArrayInputStreamStringBuffer16Unicode8StringReader2——java.ioSequenceInputStreamFileInputStreamf1,f2;Strings;f1=newFileInputStream(“file1.txt”);f2=newFileInputStream(“file2.txt”);SequenceInputStreamfs=
本文标题:55Java第10章--1(IO流处理)
链接地址:https://www.777doc.com/doc-5239784 .html