• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

File Creation Date using JNI

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi !
How can I get the creation date of a file using JNI ? Examples are always welcome !
Thanx !
Eduardo.
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Here is some sample illustration regarding getting the file create time using JNI.
I have assumed that the native code is done using VC++. I have not compiled the c++ code.
public class sample
{
public static native String getCreateDate(String filename);

static
{
try
{
System.loadLibrary(<libraryfile> ;
}
catch(Exception exp){exp.printStackTrace();}
}

public static void main(String args[])
{
if(args.length < 1)
{
System.out.println("Usage: sample <filename>");
return;
}

String filename = args[0];

String createDate = getCreateDate(filename);

System.out.println("The file :"+filename+" is created at - "+createDate);
}
}

//------------------------
//C File Header
//------------------------
/* The Header file that has to be used while writting the native code accessible
from java.
generated using : javah sample
*/
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class sample */
#ifndef _Included_sample
#define _Included_sample
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: sample
* Method: getCreateDate
* Signature: (Ljava/lang/String Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_sample_getCreateDate
(JNIEnv *, jclass, jstring);
#ifdef __cplusplus
}
#endif
#endif
Implementation for the native method Illustrated for VC++
---------------------------------------------------------
JNIEXPORT jstring JNICALL Java_sample_getCreateDate
(JNIEnv * env, jclass cls, jstring filename)
{
CString strFilename = new CString(GetStringChars(env, filename, JNI_FALSE));

//Please refer to MSDN regarding this
//
CFileFind::GetCreationTime()

CString strCreateDate = ""; //format the create date obtained from CFileFind

int len = strCreateDate.getLength();

char* pCreateDate = strCreateDate.getBuffer();

jstring createDate = NewString(env, pCreateDate, len);

strCreateDate.releaseBuffer();

pCreateDate = NULL;

return createDate;
}
In case of any clarifications refer to JNI specifiactions available with JDK documentation.
------------------
Vijay.
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic