lab08readingfiles_ProblemSet

lab08readingfiles_ProblemSet - CS100J Name Lab 08 Reading...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS100J Lab 08. Reading files Spring 2008 Name ___________________ Section time _____________ Section instructor _________________ This lab discusses input —reading a file. After the lab, study section 5.9 of the text —better yet, listen to the lectures on lesson page 5-7 of the ProgramLive CD. The lectures are much clearer than the paper version. Start this lab by downloading files Lab08.java into a directory, opening them in DrJava, and compiling. You will also need this text file: test.txt . Streams A "stream" is a sequence of data values that is processed --either read or written-- from beginning to end. When the data is being read, or input, the stream is called an "input stream"; when it is being written, or output, the stream is called an "output stream". Input/output of streams is done in Java using classes in package java.io.*; The basic way to create an input stream for a file is by creating an instance of class FileReader : FileReader fr= new FileReader( an arg that describes which file to read ) ; However, the standard way to read using FileReader fr is to read one character at a time, using function fr.read() This is too low-level for us. We would like to be able to read not one character but one line at a time. Java includes also a class BufferedReader to help us here. Instead of the above, use this: FileReader fr= new FileReader(
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern