Java Reference
In-Depth Information
// Close the input stream.
istrm.close();
}
catch (Exception e)
{
System.out.println("You had an input problem:" + e);
}
8. Let's compile this program and execute it. The output should look like
this:
File exists
File exists
This is text 0
This is text 1
This is text 2
This is text 3
This is text 4
This is text 5
This is text 6
This is text 7
This is text 8
This is text 9
This is text 1
0This is text
11This is text
12This is tex
t 13This is te
xt 14This is t
ext 15This is
text 16This is
text 17This i
s text 18This
is text 19his
Notice that the read method doesn't have any concept of lines or what
constitutes a logical unit of data. It is simply reading raw bytes in blocks of
14, so the strings of text begin to become offset when you try to read strings
of 15 bytes.
9. Let's enhance the program to write the data in fixed lengths so that when
you read it back in again, there is no offset. After the statement that creates
the output stream, add these additional statements.
Search WWH ::




Custom Search