Java JMF – Load and Play Media File

import javax.media.*;
import java.io.File;
import java.awt.*;

public class TrivialJMFPlayer extends Frame {

	public static void main (String[] args) {
		try {
			Frame f = new TrivialJMFPlayer();
			f.pack();
			f.setVisible (true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public TrivialJMFPlayer()
			throws java.io.IOException,
			java.net.MalformedURLException,
			javax.media.MediaException {

		FileDialog fd = new FileDialog
				(this, "TrivialJMFPlayer", FileDialog.LOAD);
		fd.setVisible(true);

		File f = new File(fd.getDirectory(), fd.getFile());

		Player p = Manager.createRealizedPlayer
				(f.toURI().toURL());
		Component c = p.getVisualComponent();
		add(c);

		p.start();
	}

}

Java – Convert PNG to JPEG Image File

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class ConvertImageFile {

   public static void main(String[] args) {

	BufferedImage bufferedImage;

	try {

	  //read image file
	  bufferedImage = ImageIO.read(new 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"));

	  System.out.println("Done");

	} catch (IOException e) {

	  e.printStackTrace();

	}

   }

}

Java – Change File Date / Time using Commons FileUtils

import java.io.IOException;
import org.apache.commons.io.FileUtils;

import java.io.File;

public class Main {

	public static void main(String[] args) {
		try {
			File file = new File("pic.jpg");
			long lastModified1 = file.lastModified();
			FileUtils.touch(file);
			long lastModified2 = file.lastModified();
			System.out.println("File date / time was updated: " + (lastModified2 > lastModified1));
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}

}

Output:

File date / time was updated: true

Page 1 of 512345