Sei sulla pagina 1di 16
UNIT3 {59 8sscinpuouput stream Summary of Unit 3 @ Summary ‘This unit discusses how a program written jn Java performs input! ouput operations. Asa file is a common storage medium used for data storage, the examples and discussions are mostly file related. A file is identified by its file name and path name. To manipulate a file, such as inspecting its acri (or simply Fite) object by providing a st=ing object specifying the full path of the file, including the path name and file name. Furthermore, a Fite object in Java can associate not only with a file bur also with a directory. Then, you can call methods of the File object to obrain the information about the fle. ies, ou can createa java ic.Fate “The Java standard soliwate library provides classes for performing stream-based input/output operations. Stream classes are categorised according to the type of data they process and the direction of data ow. They are surnmarised in the following table, Input | Inpurstream (e-g., Reader stream | ci lernputstrean) (e.g-) FileReader) output | Outputstzean frites stream | (e.g., Fileoutpurstrean) | (e-g-, FileWtrizer) ‘Once you are familiar with the streamn-based input/output approach, you may find such an approach flexible, as you can replace or insert 4 stream object for vacious behaviours. You can then further study the uses of other clases provided by the java.io package that are specific to other storage media of communication channels. Daring the discussion of performing inpuvoutput operations with Java, we discussed input/output operations that may fail due to an ‘exceptional condition. When the statement that performs the ‘operation fails itis known as a tuntime error or exception. In Java, aan exception is an object that encapsulates the information of the runtime error that occurred, UNITS astcinputloutputstream Unit Practice Exercises 1, Attempe the Exercises questions in Malik, D S, Janu Prognomming: From Problem Analysis to Program Design for question 7,9, 10 11, 12 in page 161 to 162. 2. Whae does it mean to say that a program is robust? 3. Why do programming languages require that variables be declared before they ate used? What docs this have to do with correctness and robustness? 4, Consider subroutine processData that has the header static void processData() throws 10Exception Write a cry. ..catch statement that calls this subroutine and prints an error message if an 1oException occurs 5. Why should a subroucine throw an exception when it encounters an error? ‘Why not just terminate the program? 6. Java has ewo types of streams: character streams and byte streams. Why? What is che difference between the two types of streams? 7. What is the point of the following statement? out = new Printlirster( new Filewriter (™data-dac") }7 Why would you need a statement that involves two different stream classes, Printliriter and FiloWriter? a

Potrebbero piacerti anche

  • WUC103 Unit2-4
    WUC103 Unit2-4
    Documento10 pagine
    WUC103 Unit2-4
    api-26781128
    Nessuna valutazione finora
  • WUC103 Unit2-3
    WUC103 Unit2-3
    Documento16 pagine
    WUC103 Unit2-3
    api-26781128
    Nessuna valutazione finora
  • WLA105 Unit4-3
    WLA105 Unit4-3
    Documento18 pagine
    WLA105 Unit4-3
    api-26781128
    Nessuna valutazione finora
  • WLA105 Unit2-1
    WLA105 Unit2-1
    Documento20 pagine
    WLA105 Unit2-1
    api-26781128
    Nessuna valutazione finora
  • WUC103 Unit2-1
    WUC103 Unit2-1
    Documento24 pagine
    WUC103 Unit2-1
    api-26781128
    Nessuna valutazione finora
  • WLA105 Unit2-4
    WLA105 Unit2-4
    Documento24 pagine
    WLA105 Unit2-4
    api-26781128
    Nessuna valutazione finora
  • WLA105 Unit5-3
    WLA105 Unit5-3
    Documento18 pagine
    WLA105 Unit5-3
    api-26781128
    Nessuna valutazione finora
  • WUC103 Unit2-2
    WUC103 Unit2-2
    Documento10 pagine
    WUC103 Unit2-2
    api-26781128
    Nessuna valutazione finora
  • WLA105 Unit5-1-2
    WLA105 Unit5-1-2
    Documento22 pagine
    WLA105 Unit5-1-2
    api-26781128
    Nessuna valutazione finora
  • WLA105 Unit4-1-2
    WLA105 Unit4-1-2
    Documento24 pagine
    WLA105 Unit4-1-2
    api-26781128
    Nessuna valutazione finora
  • WLA105 Unit2-2
    WLA105 Unit2-2
    Documento6 pagine
    WLA105 Unit2-2
    api-26781128
    Nessuna valutazione finora
  • WLA105 Unit2-3
    WLA105 Unit2-3
    Documento10 pagine
    WLA105 Unit2-3
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit5-3n4
    TCC102 Unit5-3n4
    Documento14 pagine
    TCC102 Unit5-3n4
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit5-5
    TCC102 Unit5-5
    Documento12 pagine
    TCC102 Unit5-5
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit4-5
    TCC102 Unit4-5
    Documento22 pagine
    TCC102 Unit4-5
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit5-1
    TCC102 Unit5-1
    Documento22 pagine
    TCC102 Unit5-1
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit4-4
    TCC102 Unit4-4
    Documento14 pagine
    TCC102 Unit4-4
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit5-2
    TCC102 Unit5-2
    Documento20 pagine
    TCC102 Unit5-2
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit4-3
    TCC102 Unit4-3
    Documento12 pagine
    TCC102 Unit4-3
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit4-2
    TCC102 Unit4-2
    Documento26 pagine
    TCC102 Unit4-2
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit3 2
    TCC102 Unit3 2
    Documento20 pagine
    TCC102 Unit3 2
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit4-1
    TCC102 Unit4-1
    Documento14 pagine
    TCC102 Unit4-1
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit2 Summary
    TCC102 Unit2 Summary
    Documento25 pagine
    TCC102 Unit2 Summary
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit3 4
    TCC102 Unit3 4
    Documento14 pagine
    TCC102 Unit3 4
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit3 1
    TCC102 Unit3 1
    Documento14 pagine
    TCC102 Unit3 1
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit2 3
    TCC102 Unit2 3
    Documento12 pagine
    TCC102 Unit2 3
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit3 3
    TCC102 Unit3 3
    Documento14 pagine
    TCC102 Unit3 3
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit2 5
    TCC102 Unit2 5
    Documento13 pagine
    TCC102 Unit2 5
    api-26781128
    Nessuna valutazione finora
  • TCC102 Unit2 4
    TCC102 Unit2 4
    Documento24 pagine
    TCC102 Unit2 4
    api-26781128
    Nessuna valutazione finora