03/02/2003: How Do I Load An Image and Determine Height and Width Using Java?
When loading an image over the net you frequently have to allow for long load times. The MediaTracker class is used to monitor a resource so that other things can happen (ie. threads) while the image is loading.
However, sometimes you really need for the image to totally load because you need the height and width measurements before continuing. The following code fragment show how to wait for an image to finish loading. - from Bob Withers in comp.lang.java.api.
// url is a String containing the URL of the image to load. MediaTracker tr; Image im = toolkit.getImage(url); tr.addImage(im, 0); tr.waitForID(0); // at this point the image is finished // loading and the height and width can // be determined. int w = im.getWidth(this); int h = im.getHeight(this);
03/02/2003: How Can I Improve the I/O Speed for System.out.println Using Java?
Normally, the System.out print stream has a buffer size of 128 and flushes the buffer whenever a newline character is encountered.
The following four lines of java change the buffer size to 1024 and doesn’t flush the buffer for newline characters.
FileOutputStream fdout = new FileOutputStream(FileDescriptor.out); BufferedOutputStream bos = new BufferedOutputStream(fdout, 1024); PrintStream ps = new PrintStream(bos, false); System.setOut(ps);