Archives: File Handling

Java – Extract links from HTML page

[code lang=”java”]import;
import java.util.ArrayList;

import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML.Attribute;
import javax.swing.text.html.HTML.Tag;
import javax.swing.text.html.HTMLEditorKit.ParserCallback;
import javax.swing.text.html.parser.ParserDelegator;

public class Main {

public final static void main(String[] args) throws Exception {
final ArrayList<String> list = new ArrayList<String>();

ParserDelegator parserDelegator = new ParserDelegator();
ParserCallback parserCallback = new ParserCallback() {
public void handleText(final char[] data, final int pos) {

public void handleStartTag(Tag tag, MutableAttributeSet attribute, int pos) {
if (tag == Tag.A) {
String address = (String) attribute.getAttribute(Attribute.HREF);

public void handleEndTag(Tag t, final int pos) {

public void handleSimpleTag(Tag t, MutableAttributeSet a, final int pos) {

public void handleComment(final char[] data, final int pos) {

public void handleError(final java.lang.String errMsg, final int pos) {
parserDelegator.parse(new FileReader("a.html"), parserCallback, false);


Java – Convert PNG to JPEG Image File

[code lang=”java”]import java.awt.Color;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

public class ConvertImageFile {

public static void main(String[] args) {

BufferedImage bufferedImage;

try {

//read image file
bufferedImage = File("c:\\javanullpointer.png"));

// create a blank, RGB, same width and height, and a white background
BufferedImage newBufferedImage = new BufferedImage(bufferedImage.getWidth(),
bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB);
newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, Color.WHITE, null);

// write to jpeg file
ImageIO.write(newBufferedImage, "jpg", new File("c:\\javanullpointer.jpg"));


} catch (IOException e) {





Java – Change File Date / Time using Commons FileUtils


File date / time was updated: true