Java Reference
In-Depth Information
You used character streams to handle text and byte streams for any other kind of data.
Filters were associated with streams to alter the way information was delivered through a
stream or to alter the information itself.
In addition to these classes, java.io offers other types of streams you might want to
explore. Piped streams are useful when communicating data among different threads, and
byte array streams can connect programs to a computer's memory.
Because the stream classes in Java are so closely coordinated, you already possess most
of the knowledge you need to use these other types of streams. The constructors, read
methods, and write methods are largely identical.
Streams are a powerful way to extend the functionality of your Java programs because
they offer a connection to any kind of data you might want to work with.
Tomorrow, you will use streams to read and write Java objects.
Q&A
Q A C program that I use creates a file of integers and other data. Can I read
this using a Java program?
A You can, but one thing you have to consider is whether your C program represents
integers in the same manner that a Java program represents them. As you might
recall, all data can be represented as an individual byte or a series of bytes. An
integer is represented in Java using four bytes arranged in what is called big-endian
order. You can determine the integer value by combining the bytes from left to
right. A C program implemented on an Intel PC is likely to represent integers in
little-endian order, which means that the bytes must be arranged from right to left
to determine the result. You might have to learn about advanced techniques, such
as bit shifting, to use a data file created with a programming language other than
Java.
Q Can relative paths be used when specifying the name of a file in Java?
A Relative paths are determined according to the current user folder, which is stored
in the system properties user.dir . You can find out the full path to this folder by
using the System class in the main java.lang package, which does not need to be
imported.
Call the System class getProperty( String ) method with the name of the property
to retrieve, as in this example:
String userFolder = System.getProperty(“user.dir”);
The method returns the path as a string.
 
Search WWH ::




Custom Search