Sitemap    
  Home Food Photographs IT Parenting Resources Learning  
JAVA
J2SE
How to get created date in Java
How to read and write a file
Install and run program
JSP
Servlet
Spring
Struts2
Webservice
How to get created date in Java
Usually programmers will use Windows machine to write their programs, compile and then deploy it to *NIX environment in a production setup. You can achieve this with JAVA, surely not with languages like "C". Because objective is to compile and deploy on any platform JAVA does not provide function like File.getCreateDate(). Reason being many platforms particularly with low memory footprints only provide last modified date.

There are two work arounds to achieve this
1. Either we can use some native OS command to get create date and then fetch that value in JAVA. e.g. Use Command prompt in Windows or Shell Script in *NIX environment.
2. Use JNI to run a native code function like function written in "C"

I found this solution on http://www.daniweb.com/. I had difficulty executing CMD through JAVA probably due to permissions or virus scanner. So I created a batch file to execute dir command. Also it needs to use dir /TC command to display create date.
getcreatedate.bat

GetCreateDateInWin.java
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class GetCreateDateInWin
{
  public static void main(String args[]) throws Exception {
    Process process = null;
    BufferedReader br = null;
    try
    {
      String filename = "C:/apps/hsqldb/bin/getcreatedate.bat";
      process = Runtime.getRuntime().exec(filename);
      br = new BufferedReader(new InputStreamReader(process
          .getInputStream()));
      String line = null;
      while ((line = br.readLine()) != null)
      {
        System.out.println(line);
      }
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    finally
    {
      process.destroy();
      br.close();
    }
  }
}


Now parse this output to get create date

ADD TO DEL.ICIO.US ADD TO DIGG ADD TO FURL ADD TO REDDIT ADD TO STUMBLEUPON ADD TO TECHNORATI FAVORITES ADD TO SQUIDOO ADD TO YAHOO MYWEB ADD TO ASK ADD TO GOOGLE
Post your comments:
Your Name: 
Security check:
Your Comment: 1500 chars
Latest
How to loop arraylist JAVA6 Syntax
How to iterrate through ArrayList and display multiple rows using for loop JAVA6 syntax..
Java JSP  2010-Oct-12
How to loop arraylist
How to iterrate through ArrayList and display multiple rows using for loop, JSTL tags..
Java JSP  2010-Oct-12
Consumer using JAX WS Dispatch API and DOM parser 1
Access/Consume Webservice using Servlet, JAX-WS Dispatch API dynamic client and parsing SOAP response using DOM parser...
Java Webservice  2010-Sep-20
Simple Java first CXF Webservice 4
Building Simple Java first CXF webservice using CXFServlet, Spring, jaxws:endpoint, @WebService, @SOAPBinding, @WebResult
Java Webservice  2010-Sep-19
Simple Java first CXF Webservice 3
Building Simple Java first CXF webservice using CXFServlet, Spring, jaxws:endpoint, @WebService, @SOAPBinding, @WebResult
Java Webservice  2010-Sep-18
Simple Java first CXF Webservice 1
Building Simple Java first CXF webservice using CXFServlet, Spring, jaxws:endpoint, @WebService, @SOAPBinding, @WebResult
Java Webservice  2010-Sep-18
Simple Java first CXF Webservice 2
Building Simple Java first CXF webservice using CXFServlet, Spring, jaxws:endpoint, @WebService, @SOAPBinding, @WebResult
Java Webservice  2010-Sep-18
Encoding special characters in userinput or on server
Encoding can be done either in Javascript or JAVA encodeURIComponent, escape, java.net.URLEncoder..
Java JSP  2010-Aug-09
Jstl fmt tag i18n formatdate formatcurrency
fmt:setBundle, native2ascii.exe, fmt:message, fmt:setLocale, fmt:formatDate, fmt:formatNumber type=currency..
Java JSP  2010-Aug-05
How to read and write a file
How to read and write a file java.io.BufferedReader,java.io.FileReader, InputStreamReader ...
Java J2SE  2010-Aug-04
jQuery validate form using ajax 2
How to validate/submit form using ajax and jQuery input#, ($.ajax)..
Javascript  2010-Jul-23
jQuery validate form using ajax 1
How to validate/submit form using ajax and jQuery ($.ajax)..
Javascript  2010-Jul-23
How to create datasource in RAD Websphere
Create JDBC provider, datasource and JAAS security setup, JDBC connection URLs
Servers Websphere  2010-Jul-08
Get Started 4
Struts2 framework structure, how various components fit together
Java Struts2  2010-Jul-07
How to populate a form when JSP is called first time
This is achieved throught setting bean in request, using frameworks like Struts2, Spring3..
Java JSP  2010-Jul-07
Spring3 And Hibernate 4
Spring3 and Hibernate 3.5.3 working together @Controller, @RequestMapping, @InitBinder, HibernateTransactionManager, LocalSessionFactoryBean, HibernateTemplate
Java Spring  2010-Jul-07