Recent Notes

Displaying keyword search results 1 - 10
Created by alfa on June 03, 2011 09:08:52    Last update: June 03, 2011 09:08:52
import java.util.Arrays; public class Array...
Created by alfa on April 08, 2011 12:33:08    Last update: April 08, 2011 12:33:08
This example captures the screen of the current Java application window, instead of the full screen. import java.io.*; import java.awt.*; import ...
Created by nogeek on April 07, 2011 21:30:54    Last update: April 07, 2011 21:30:54
This is the opposite of parsing. You can use javax.xml.transform.Transformer to output a DOM tree to a file. import java.io.*; import javax.xml.parsers.Docu...
Created by alfa on April 06, 2011 12:48:44    Last update: April 06, 2011 12:48:44
package com.demo.io; import java.io.*; ...
Created by Dr. Xi on January 14, 2010 00:28:27    Last update: March 30, 2011 15:37:44
A task that a Java developer does so frequently is to find out where a certain class can be found - to resolve compilation errors, classpath issues, or version conflicts of the same class introduced by multiple class loaders. A long while back I wrote a simple Perl script to perform the task. Later I was informed that there are Swing based Jar Browser and Jars Browser . Then, there are a couple of shell one-liners: # one liner 1 find -name "*.jar" -print0 | xarg... But all of them share the same problem: if a class is in a jar nested in another jar, it cannot be found. Such is the case for a class inside a jar under the WEB-INF/lib directory of a...
Created by Dr. Xi on March 02, 2011 11:39:18    Last update: March 09, 2011 12:19:30
Some peculiarities about Java PrintWriter: PrintWriter never throws any exceptions. From JavaDoc : Methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError(). When error occurs, you'll never know anything more than that it occured, because checkError returns boolean. When a character is out of the range of the character encoding of the PrintWriter, it prints a question mark (?). But this is not an error. Test code: import java.io.*; public class TestPrintWri... Latin1 test result: java TestPrintWriter iso-8859-1 | od -bc 000000... UTF-8 test result: java TestPrintWriter utf-8 | od -bc 0000000 141... Also, the constructor throws a FileNotFoundException when you try to write to a...
Created by Dr. Xi on March 01, 2011 16:11:50    Last update: March 01, 2011 16:11:50
Java PrintWriter is buffered. You can turn on autoFlush, but it does'nt work for all methods. Test code: import java.io.*; public class TestPrintWri... Output: [START] Test PrintWriter Auto-flush only work...
Created by Dr. Xi on August 27, 2010 22:35:53    Last update: August 27, 2010 22:35:53
This example decompresses a gzip compressed file with java.util.zip.GZIPInputStream . The input is assumed to be Base64 encoded after being gzipped (such would be the case when binary data is transmitted within an XML file). You don't need the Base64InputStream if the data is not Base64 encoded. import java.io.*; import java.util.zip.GZIPInpu...
Created by Dr. Xi on August 24, 2010 21:59:22    Last update: August 24, 2010 21:59:22
This class decodes a Base64 encoded file with the Apache commons codec package: import java.io.*; import org.apache.commons.cod...
Created by Dr. Xi on August 03, 2010 16:29:35    Last update: August 03, 2010 16:36:50
This utility converts unicode escape strings in a file to UTF-8 encoded. Suppose you received a properties file with contents like: # @(#)codepoint_zh_CN.properties 1.4 05/09/27 #... You can use this utility to convert it to UTF-8 and view or edit. import java.io.*; /** * Reads file with... This utility is equivalent to: native2ascii -reverse -encoding utf-8 using the standard Java native2ascii utility.
Previous  1 2 Next