IO Section Index | Page 12
Look at this following article in Sun's Java Developer Connection specifically in the section titled Compression. They have sample code for creating a zip file using java.util.zip package. Tuning...more
(...or any other IO method that wraps read(), like BufferedReader.readLine(). Calling thread.interrupt() does nothing.) You can't. That's the way it's supposed to work. One workaround is to use ...more
Is there any way to communicate between two classes within an application using InputStreams and OutputStreams?
The PipedInputStream/PipedReader and PipedOutputStream/PipedWriter streams provide synchronized I/O across threads, from within one class or multiple classes. The following example demonstrates th...more
There is a free printf equivalent at Acme. Staying with the standard Java classes, you would use the NumberFormat and DateFormat classes to help you format the output.more
Exactly how depends upon which stream you are reading from. If you are reading with the read() method of InputStream/Reader, this will return -1 on EOF. If however you are using BufferedReader.rea...more
First - both Absolute and Canonical forms are OS dependent per the API documentation for java.io.File. Second - Absolute is not absolute. It is not a resolved path name. If File f is not alread...more
The ZIP and JAR reading classes are found in the java.util.zip and java.util.jar packages respectively. The following demonstrates reading from a ZIP file, listing all the files in the zip and dis...more
When using object streams over sockets, I have to flush the streams after each write operation. In fact I even have to flush the output stream soon after creation. Is there a way out of this?
The ObjectOutput interface provides a flush() method, implying that implementations are allowed to buffer the output. The semantics of buffered output are such that if you want the data to be se...more
Could you describe the architecture behind jGuru.com: JSP, Servlets, database, servers, transactions etc...?
[Updated Nov 20, 2002 to remove old description and point at some articles. TJP] jGuru.com Case-Study. Little Nybbles of Development Wisdom.more
How can I get an event or notification when a file is changed or modified using standard java.io classes?
There is no built in support for this capability.
There is no built-in support for this. Basically, you must create a service on the server that when requested returns a list of available files and directories.
I'm writing to a socket using a buffered stream. When control returns after write() is invoked, has the data been sent over the network or just copied to the buffer? How does the user get notification of a network failure if the data is just put into the buffer?
The data is sent only when the buffer is full or flush() is invoked on the buffered stream. If the network fails (e.g. the remote host closes the socket), an IOException will be thrown the next ti...more
StringBufferInputStream has been deprecated; the documentation recommends you use StringReader instead. Yet, many stream-related methods in other classes (often those that predate the deprecation) will only accept an InputStream. How does one send an InputStream that came from an in-memory string?
StringBufferInputStream has been deprecated; the documentation recommends you use StringReader instead. Yet, many stream-related methods in other classes (often those that predate the deprecation)...more
The Java Communications API (http://java.sun.com/products/javacomm/index.html) provides support for accessing RS232 serial ports and IEEE 1284 parallel ports.more
The File class includes an exists() method that reports on the existence of a file. The method returns false to mean the file doesn't exist, true if it does.