<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>High Fibre Programming &#187; modified</title>
	<atom:link href="http://www.4pmp.com/tag/modified/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.4pmp.com</link>
	<description>PHP, MySQL, C, Java, Linux and other great after dinner speech topics</description>
	<lastBuildDate>Thu, 08 Jul 2010 07:35:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Java: touch &#8211; set file last modified time</title>
		<link>http://www.4pmp.com/2009/12/java-touch-set-file-last-modified-time/</link>
		<comments>http://www.4pmp.com/2009/12/java-touch-set-file-last-modified-time/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 10:30:58 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[modified]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[touch]]></category>

		<guid isPermaLink="false">http://www.4pmp.com/?p=217</guid>
		<description><![CDATA[I just discovered that I need to touch() a file in Java.   It appears there isn&#8217;t a way to do this using the standard Java library, so I rolled my own:

import java.io.*;
import java.util.Date;

class Touch
{
    /**
     * Touches a given file
     *
  [...]]]></description>
			<content:encoded><![CDATA[<p>I just discovered that I need to <a href="http://www.computerhope.com/unix/utouch.htm">touch()</a> a file in Java.   It appears there isn&#8217;t a way to do this using the standard Java library, so I rolled my own:</p>
<pre class="brush: java;">
import java.io.*;
import java.util.Date;

class Touch
{
    /**
     * Touches a given file
     *
     * @author Nick Giles &lt;http://www/4pmp.com/&gt;
     */
    public static void main(String args[])
    {
        try
        {
            // Create a new file object for the file we want to touch
            File f = new File(&quot;touch.txt&quot;);

            // See if the file already exists
            if (f.exists())
            {
                // The file already exists, so just update its last modified time
                if (!f.setLastModified(System.currentTimeMillis()))
                {
                    throw new IOException(&quot;Could not touch file&quot;);
                }
            }
            else
            {
                // The file doesn't exist, so create it
                f.createNewFile();
            }
        }
        catch (SecurityException e)
        {
            System.err.println(&quot;Security Error: &quot; + e.getMessage());
        }
        catch (IOException e)
        {
            System.err.println(&quot;IO Error: &quot; + e.getMessage());
        }
    }
}
</pre>
<p>Just like the Linux command, if the input is a directory then it will update the last modified time for the directory but not recurse into it.   If you need to recurse then the above can easily be extended to recurse itself using f.isDirectory() and f.listFiles().   If anyone needs this then just let me know and I&#8217;ll rustle it up, but for now I&#8217;ll leave that as en exercise for the reader <img src='http://www.4pmp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.4pmp.com/2009/12/java-touch-set-file-last-modified-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
