Rabu, 19 Disember 2012

CHAPTER 10 : STREAMS AND FILE I/O

10.1 An overview of streams file i/o

        - We can use file to to store input for a program or to hold output from a program.In java,file i/o,as
           well as simple keyboard and screen i/o.
        - A stream is a flow of data.The data might be character,number, or bytes consisting of binary of
          data .if the data flows into your program,the stream is called an input stream
        - For example,if an input stream is connected to the keyboard,the data flows from the keyboard into
          your program.


   WHY USE FILES FOR I/O

         -The keyboard input and the screen output we have use so far deal with tempory data.When the
           program ends,the data type of keyboard and left on screen go way.files provide you with away to
          to store data permanently.
        -An input file can used over and over again by different programs,without the need to type the data 
          again for each program.files also provided you with convinient way to deal with large quentities\
         of data.


10.2 Text-file i/0

      -The class PrintWriter in java class library defines the metods that we will need to create and write to 
        will need to create and write to a text file.This class is the preferred one for writting to a text file.
      -Before we can write to text file,we must connect it to an output stream.That is,we open the file.
        To do this,we need the name of file as a string.the file has a name like out.

    GOTCHA

    -When you open a text file or a binary file for output,you alwys begins with an empty file.if no existing
      file has the given name,the constructor that you invoke will create an empty file with the name

Appending to a text file

     -We may simply want to add,or append,more data to the end of the file.to append programs output to
       the text file named by the string variable.
     -it's old content will remain,the program's otput will be replaced after those content.but if the files does
       not already exist, java will create an empty file.


10.3 TECHNIQUES FOR ANY FILE

       -The class file provides a way to represent that file in a general way.Astring such as"traesure.txt"
         might be a file name,but it has only string properties, and java does not recognise it as file name.g as
       - Althought some stream classes have constructor that accept a string name of a file,some do not
          some stream clases have constructor that accept only a file object as an argument.we already saw
         in the previious section that when reading a text file,we cannot

Tiada ulasan:

Catat Ulasan

Related Posts Plugin for WordPress, Blogger...