Lastmodified date

public void choosefile() {
          JFileChooser fc = new JFileChooser();
          int result = fc.showOpenDialog(null);     
          if (result == JFileChooser.CANCEL_OPTION)
               JOptionPane.showMessageDialog(null, "Operation cancelled");
          else {
               File filename = fc.getSelectedFile();
               String s = "Name: " + filename.getName() + "\n" +
               "Path: " + filename.getPath() + "\n" +
               "Parent:" + filename.getParent() + "\n" +
               "Length:" + filename.length() + "\n" +
               "Can Read: " + filename.canRead()     + "\n" +
               "Can Write: " + filename.canWrite() + "\n" +
               "Last Modified: " + filename.lastModified();
               txtArea.setText(s);
Above are my methods for choosing the file and thenon displaying its various properties
Below are my results:
Name: xuweiliangvictor.jpg
Path: D:\xuweiliangvictor.jpg
Parent:D:\
Length:12512
Can Read: true
Can Write: true
Last Modified: 1177514242366
May I know how could I display the last modified date as : DayofWeek Month Day Time Zone Year?
Like Thu Apr 10 12:17:04 SGT 2003
Many many thanks in advance :)

As the API states, lastModified returns:
<quote>
A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs.
</quote>
Construct a java.util.Date out of that and format the date and time as you like using a java.text.SimpleDateFormat. See the API for details.

Similar Messages

  • Prompt i want to display as From Date & To Date - as a lastmodified date

    Hi All,
    i want to displayed as a from date and to date from the column name as lastmodified date in the prompt. in the prompt i selected the between option it is displayed as a between and not as a from date - to date.
    From Date(prompt button as calender)----------To Date
    Thanks
    Chandra

    Hi,
    can u pls look into the below link
    http://docs.oracle.com/cd/E10415_01/doc/bi.1013/e12188/T421739T524310.htm

  • Formatting the return value of: File(myFile).lastModified()

    I'm checking file date and time stamps:
    myDate = File(myFile).lastModified()Is there a way to format the return value?
    myDate equals: 1205166439145I'd like to see something like:
    03/10/2008  12:27 PMI'm using the following code to print the value:
    System.out.println(myDate);

    Awesome! I really, really appreciate the help and the sample code!
    Successful Output:
    K:\COMMON\ITS\STEVEB\java\CompareFileDates>java CompareFileDates
    execution continuing...
    test1.steve (3/10/08 12:27 PM) is older than test2.steve (3/10/08 1:33 PM)Error free code:
    import java.io.File;
    import java.lang.Object;
    import java.util.Date;
    import java.text.Format;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    public class CompareFileDates {
      public static void main(String[] args) {
        String file1_stat = null;
        String file2_stat = null;
        String file1 = "test1.steve";
        String file2 = "test2.steve";
        long date1 = 0;
        long date2 = 0;
        String finalDate1 = null;
        String finalDate2 = null;
        boolean file1Exists = (new File(file1)).exists();
        if (file1Exists) {
            // File or directory exists
            file1_stat = "does exist";
            // Get the timestamp from file 1 and format it
            date1 = (new File(file1)).lastModified();
         Date newDate1 = new Date(date1);
         DateFormat df = new SimpleDateFormat();
         finalDate1 = df.format(newDate1);
         //System.out.println(file1 + " date: " + finalDate1);
        else {
            // File or directory does not exist
            file1_stat = "does not exist";
        boolean file2Exists = (new File(file2)).exists();
        if (file2Exists) {
            // File or directory exists
            file2_stat = "does exist";
            // Get the timestamp from file 2 and format it
            date2 = (new File(file2)).lastModified();
         Date newDate2 = new Date(date2);
         DateFormat df = new SimpleDateFormat();
         finalDate2 = df.format(newDate2);
         //System.out.println(file2 + " date: " + finalDate2);
        else {
            // File or directory does not exist
            file2_stat = "does not exist";
        if ((file1Exists == false) || (file2Exists == false)) {
                System.out.println("aborting program...");
        else { 
           System.out.println("execution continuing...");
           String relation;
           if (date1 == date2)
             relation = "the same age as";
           else if (date1 < date2)
             relation = "older than";
           else
             relation = "newer than";
           System.out.println(file1 + " (" + finalDate1 + ")" + " is " + relation + ' ' + file2 + " (" + finalDate2 + ")");
    }

  • File.lastModified() not working in MAC OS

    Hi all,
    Iam trying to get the lastmodified time of a file using this
            File newFile=new File(uploadFilePath); //uploadFilePath has the path of the file.
            String newFile_Name=newFile.getName();
            long lastmodified=newFile.lastModified(); The above is working in windows but not in MAC. in MAC i get the lastmodified time as 0. I
    s there anyother functionality to get this in MAC. or is it the problem with the path?.
    For eg. the uploadFilePath in PC will be like this
    C:\Documents and Settings\Tanuja\Desktop\File\file_management.txt
    where as in MAC file path of a selected file will be like this.
    /Users/Tanuja/Desktop/file_management.txt
    is this path makes difference or iam i going wrong somewhere?
    could not figure out.
    Thanks,
    Thanuja.

    I found where the problem is. Using the file chooser i selected a file and got the file path and my code deals witht the path as below:
    String uploadFilePath=/Users/Tanuja/Desktop/file_management.txt
    File newFile1=new File(uploadFilePath);
    //Check  whether file exists or not
    if(newFile1.exists()==true)
                out.println("exists");
            else
                out.println("does not exists");
    Result: does not exists
    So i tried by passing the absolute path but all in vain. I get the same result.
    Absolute path: C:\Users\Tanuja\Desktop\file_management.txt
    String uploadFilePath=/Users/Tanuja/Desktop/file_management.txt
    File newFile1=new File(uploadFilePath);
    String abslolutePath=newFile1.getAbsolutePath();
    File newFile=new File(abslolutePath);
    if(newFile.exists()==true)
                out.println("exists");
            else
                out.println("does not exists"); why its not detecting the file though the file path it returned is correct?.
    since it is not detecting the file i got the lastmodified as 0.
    iam using commons upload to upload the file. how commons package is able to detect the file and upload. My upload process is success. but before uploading the file i need to validate it by gettting the lastmodified date. Its not working.
    Any suggestions?
    Thanks,
    Thanuja.

  • Date / Delimiting Problems

    I'm writing a FileFinder Class at a moment, which offers a Find File Dialog (who would have thought ;-)).
    Now I got a problem:
    1) I store all data connected with a match in a special class (filename, the subdirectory in which the file is placed and so on). Nothing special, except for the lastModified date:
    Shall I store it as long (which shows the time in ms) and convert it when I output the value or in a Date Object?

    what's wrong with the java.io.File class?
    Its lastModified() method returns a long, which won't be very sensible for most clients. Best to create a java.util.Date from that and format it so the date and time of last modification is displayed (e.g., SimpleDateFormat with "MMM-dd-yyyy hh:mm:ss" or something like that)
    %

  • Redo Log Last modified date

    Hi All,
    Couple of day's back we have set Hot back up mode for 11g database server from cold back up,
    after this reado log's last modified date is not getting updated and redolog last modified date is get's updated only when we restart the database,
    There is no error message in the alert log and data base running normally without any issues,
    can you please advise me why redo logs LastModified date is not getting updated.
    Thanks
    sankar

    user12994238 wrote:
    Hi All,
    Couple of day's back we have set Hot back up mode for 11g database server from cold back up,
    after this reado log's last modified date is not getting updated and redolog last modified date is get's updated only when we restart the database,
    There is no error message in the alert log and data base running normally without any issues,
    can you please advise me why redo logs LastModified date is not getting updated.
    Thanks
    sankarcould it be that the timestamp is not updated until such time as the file is closed? That would be easy enough to observe/test.

  • HTTPServletResponse.setDateHeader  messing up the date?

    The code is simple:
         File f = getNewCacheFile((String)getProperty(CACHE_KEY));
    long lastModified = f.lastModified();
         Date dt = new Date(lastModified);
         System.out.println(dt.toString());                    
         p_response.setDateHeader("Expires", lastModified + lExpireInterval);
         p_response.setDateHeader("Last-Modified", lastModified);
    The date/System.out is for debugging (it prints out the correct value)..
    Sample output:
    System.out.print -- > Wed May 21 08:09:07 PDT 2003
    Actual Header LastModified Header (received on client end)
    Wed, 21 May 1983 15:55:24 GMT
    any Thoughts on this? (the javadoc states that the setDateHeader does receieve a epoch time in milliseconds...)

    Never Mind, the tool (NaviScopre) I was using seams to not be interpreting the last-modified field correctly. When I switched to Etherreal, it shows the correct values, and the proxy does in fact honer the correct values.

  • Changes to lastmodified column in aboutToUpdate event doesn't work

    We use the following code in the aboutToUpdate event to set the lastmodified date on changed object:
    DatabaseRow row = event.getRow();
    lastModified = now();
    Descriptor descriptor = event.getSession().getDescriptor(this);
    DatabaseMapping mapping = descriptor.getMappingForAttributeName("lastModified");
    if (mapping != null) {
    String modField = ((DirectToFieldMapping) mapping).getFieldName();
    DatabaseTable table = descriptor.getDefaultTable();
    String qualifier = table.getQualifiedName();
    if (qualifier.length() > 0) {
    modField = qualifier + "." + modField;
    row.put(modField, lastModified);
    This code is in the aboutToUpdate event on the superclass in the hierarchy.
    However, on one of the machines, this code doesn't update the lastmodified for one of the types of objects. Lastmodified is updated on objects of other types on that machine. The same code works fine on objects of all types on other machines.
    I enabled the logSQL mechanism of TOPLink and found that update SQL was not modifying the lastModified field. However, when I look at the code through debugger, I do see the lastmodified in the DatabaseRow of the event.
    After having verified the versions of TOPLink and jdbc driver, I'm trying to debug the issue by previewing the sql that is generated by TOPLink. These are the 2 things I have tried so far and both of them return null SQL String:
    1.
    WriteObjectQuery dbQuery = new WriteObjectQuery();
    dbQuery.setObject(this);
    try {
    dbQuery.prepareCall(event.getSession(), row);
    String query = dbQuery.getSQLString();
    } catch (QueryException qe) {
    qe.printStackTrace();
    2.
    DatabaseQuery d = event.getQuery();
    d.prepareCall(event.getSession(), d.getTranslationRow());
    String query2 = d.getSQLString();

    Very strange. Is there anything special about the machine or the class that it does not work for? Did you verify the event is being raised for that class on that machine?
    The only thing that I can think of that would cause this is if the class were using custom SQL or a custom query for its update.
    The reason that you do not see the SQL when creating a WriteObjectQuery is that it does not generate it's SQL until after the prepare as it must first determine if an insert or update is required. It also will not work with an UpdateObjectQuery, because the update SQL is dynamic (depends on what was changed) so the SQL cannot be prepared in the query.
    I believe the following will return the SQL that TopLink would generate for an update, provided you use the row from the aboutToUpdateEvent.
    UpdateObjectQuery dbQuery = new UpdateObjectQuery();
    dbQuery.setObject(event.getObject());
    dbQuery.setModifyRow(event.getRow());
    dbQuery.prepareCall(event.getSession(), event.getQuery().getTransactionRow());
    String query = dbQuery.getSQLString();

  • Finding and showing file date/time i'm referencing on

    How can I find and show on page the date and time parameters of file on which i'm referencing with using an JSP? I tried it with java.io.*,
    <%@ page import="java.io.*"%>
    <%@ page import="java.awt.*,javax.swing.text.*"%>
    <%@ page contentType="text/html; charset=windows-1250"%>
    <%
    File u_file=new File("http://oracle1/pn/index.html");
    long dat=u_file.lastModified();
    Date u_date=new Date(dat);
    %>
    <%=u_file.getPath()%>
    <%=u_file.getName()%>
    <%=u_file.isFile()%>
    <%=u_date%>
    but the date was always 0(1.1.1970) ,result of isFile was null, but result of Pathname and Name was correct.
    What is wrong?

    From the JSP, if you say, File file = new File(path);
    It will try to search for the file starting from the bin directory (I am using tomcat). So, you need to give the full path to the file from there.
    For example, if your file is in, webapps/examples/html/ directory, you need to use something like this,
    File file = new File("../webapps/examples/html/index.html");
    You can't give URL as the file name/path. You can't access Oracle's file system!!!
    Hope this helps.
    Sudha

  • Need help - select data from NCLOB column problem

    Hi,
    Im having problem retrieving data from NCLOB columns via ODBC. After SQLExecdirect on my SELECT statement call to SQLFetch gives me following error:
    ORA-24806 LOB form mismatch
    I tried following two ways of data retrieval:
    SQLExecDirect(hstmt,(SQLTCHAR*)szSQLStatement,SQL_NTS);
    SQLBindCol(hstmt,3,SQL_C_TCHAR,chBuffer,sizeof(chBuffer),&iDataLen);
    SQLFetch(hstmt);
    OR
    SQLExecDirect(hstmt,(SQLTCHAR*)szSQLStatement,SQL_NTS);
    SQLFetch(hstmt);
    SQLGetData(hstmt,3,SQL_C_TCHAR,chBuffer,sizeof(chBuffer),&iDataLen);
    Both times call to SQLFetch gives me ORA-24806 LOB form mismatch error.
    INSERT and UPDATE for this table works just fine.
    If I change NCLOB type to CLOB works just fine, but I will be storing Unicode data, so using CLOB cant be a solution
    Any ideas appreciated.
    Thanks in advance,
    Vlad
    Server:
    Oracle 9.2 database on Windows 2000 Server
    NLS_LANGUAGE = AMERICAN
    NLS_TERRITORY = AMERICA
    NLS_CHARACTERSET = WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET = AL16UTF16
    Client:
    Unicode C++ application, connects via Oracle 9.2 ODBC driver on Windows XP
    NLS_LANG = AMERICAN_AMERICA.WE8MSWIN1252
    CREATE TABLE my_nclob_table (
         id number (10,0) NOT NULL ,
         name nvarchar2 (255) NOT NULL ,
         description nvarchar2 (255) NULL ,
         definition nclob NOT NULL ,
         creation date NOT NULL ,
         lastmodified date NOT NULL ,
         CONSTRAINT PK_cat_pricelist PRIMARY KEY
              id
    #define     nil NULL
    #define     null NULL
    #define     SQL_ERR(__sqlerr__)     (((__sqlerr__) != SQL_SUCCESS) && ((__sqlerr__) != SQL_SUCCESS_WITH_INFO))
    #define     STOP_IF_SQL_ERR(__sqlerr__)                                                                 \
                                                      do                                                       \
                                                           if (SQL_ERR(__sqlerr__)) goto stop_;     \
                                                      } while (false)                                                  
    void eqTestOracleLOBSelect(void)
         SQLHENV henv     = null;
         SQLHDBC hdbc     = null;
         SQLHSTMT hstmt     = null;
         SQLRETURN retcode     = SQL_SUCCESS;
         TCHAR          szSQLStatement[]     = T("select id, name, definition from mynclob_table");
         int               iFetchedRows = 0;
         TCHAR          szMsg[512];
         TCHAR          chBuffer[2049];
         SQLLEN          iDataLen = 0;
         try
              retcode = eqOpenConnectionODBC(_T("myTestDsn"),_T("user"),_T("pwd"),henv,hdbc);
              STOP_IF_SQL_ERR(retcode);
              retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
              STOP_IF_SQL_ERR(retcode);
              retcode = SQLExecDirect(hstmt,(SQLTCHAR*)szSQLStatement,SQL_NTS);
              STOP_IF_SQL_ERR(retcode);
              retcode = SQLBindCol(hstmt,3,SQL_C_TCHAR,chBuffer,sizeof(chBuffer),&iDataLen);
              STOP_IF_SQL_ERR(retcode);
                   while (retcode == SQL_SUCCESS)
                        retcode = SQLFetch(hstmt);
                        if (retcode == SQL_NO_DATA)
                             retcode = SQL_SUCCESS;
                             break;
                        STOP_IF_SQL_ERR(retcode);
                   //     retcode = SQLGetData(hstmt,3,SQL_C_TCHAR,chBuffer,sizeof(chBuffer),&iDataLen);
                   //     STOP_IF_SQL_ERR(retcode);
                        ++iFetchedRows;
         stop_:
              if (SQL_ERR(retcode))
                   MessageBox(null,_T("SQL statement execution error."),_T("Error"),MB_OK);
                   eqShowStatementError(SQL_HANDLE_STMT,hstmt,retcode);
              } else     {
                             _stprintf(szMsg,_T("SQL execution success. Fetched rows: %ld"),iFetchedRows);
                             MessageBox(null,szMsg,_T("Success"),MB_OK);
         catch(...)
              MessageBox(null,_T("Unknown exception in eqTestOracleLOBSelect"),_T("Unknown exception"),MB_OK);
         if (hstmt != null)
              SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
              hstmt = null;
         if (hdbc != nil)
              SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
              hdbc = nil;
         if (henv != nil)
              SQLFreeHandle(SQL_HANDLE_ENV, henv);
              henv = nil;
    SQLRETURN eqOpenConnectionODBC(TCHAR          *szDSN,
                                       TCHAR          *szUser,
                                       TCHAR          *szPassword,
                                       SQLHENV     &henv,
                                       SQLHDBC &hdbc)
         SQLRETURN retcode;
         henv = nil;
         hdbc = nil;
         //Allocate environment handle
         retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
         STOP_IF_SQL_ERR(retcode);
         //Set the ODBC version environment attribute
         retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
         STOP_IF_SQL_ERR(retcode);
         // Allocate connection handle
         retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
         STOP_IF_SQL_ERR(retcode);
         // Set login timeout to 5 seconds.
         SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (void*)5, 0);
         STOP_IF_SQL_ERR(retcode);
         retcode = SQLConnect(hdbc, (SQLTCHAR*)szDSN, SQL_NTS,
                                            (SQLTCHAR*)szUser, SQL_NTS,
                                            (SQLTCHAR*)szPassword, SQL_NTS);
    stop_:
              if (SQL_ERR(retcode))
                   MessageBox(null,_T("Connection Error."),_T("Error"),MB_OK);
                   if (hdbc != nil)
                        eqShowStatementError(SQL_HANDLE_DBC, hdbc,retcode);
                        SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
                        hdbc = nil;
                   if (henv != nil)
                        eqShowStatementError(SQL_HANDLE_ENV, henv,retcode);
                        SQLFreeHandle(SQL_HANDLE_ENV, henv);
                        henv = nil;
              } else MessageBox(null,_T("Connected."),_T("Success"),MB_OK);
         return retcode;
    void eqShowStatementError(SQLSMALLINT chHandleType, SQLHANDLE hHandle,long lErrOrig)
         SQLRETURN          nErr          = SQL_SUCCESS;
         int                    nRecNum = 1;
         SQLTCHAR          szSqlState[6];
         SQLTCHAR          szMsg[SQL_MAX_MESSAGE_LENGTH];
         SQLSMALLINT          nMsgLen;
         SQLINTEGER          nNativeError;
         while ((nErr = SQLGetDiagRec(chHandleType,hHandle,nRecNum,
                                            szSqlState, &nNativeError,
                                            szMsg, sizeof(szMsg), &nMsgLen)) != SQL_NO_DATA)
              szSqlState[5] = 0;
              MessageBox(NULL,(const TCHAR *)szMsg,_T("ODBC Error"),MB_OK);
              ++nRecNum;

    Yes, the 9.2.0.2 driver can be downloaded from OTN. I don't believe it will solve your particular problem, but it will help in general. If you don't grab the latest version, you'll probably have to chack the "Force SQL_WCHAR Support" option in the DSN configuration.
    From the help file
    "The C data type, SQL_C_WCHAR, was added to the ODBC interface to allow applications to specify that an input parameter is encoded as Unicode or to request column data returned as Unicode. The macro SQL_C_TCHAR is useful for applications that need to be built as both Unicode and ANSI. The SQL_C_TCHAR macro compiles as SQL_C_WCHAR for Unicode applications and as SQL_C_CHAR for ANSI applications."
    My first thought would be that your application is not being compiled as Unicode. If you substitute SQL_C_WCHAR for SQL_C_TCHAR when you're dealing with NCLOB columns, I suspect you'll have better luck.
    More help file
    "The SQL data types, SQL_WCHAR, SQL_WVARCHAR, and SQL_WLONGVARCHAR, were added to the ODBC interface to represent columns defined in a table as Unicode. These values are potentially returned from calls to SQLDescribeCol, SQLColAttribute, SQLColumns, and SQLProcedureColumns. In Oracle release 8.1.7.0.0 or 9.0.1.0.0, the Oracle database does not support encoding columns as Unicode. These values would not be returned from the ODBC Drivers for Oracle release 8.1.7.0.0 or for Oracle 9.0.1.0.0 databases.
    In Oracle release 9.2.0.0.0, Unicode encoding was supported for SQL column types NCHAR, NVARCHAR2, and NCLOB. In addition, Unicode encoding was also supported for SQL column types CHAR and VARCHAR2 if the character semantics were specified in the column definition.
    Starting with release 9.2.0.2.0, the ODBC Driver supports these SQL column types and maps NCHAR to the SQL data type SQL_WCHAR, NVARCHAR2 is mapped to SQL_WVARCHAR, and NCLOB is mapped to SQL_WLONGVARCHAR. The SQL CHAR column is mapped to SQL_WCHAR and the VARCHAR2 column is mapped to SQL_WVARCHAR if the character semantics are specified for the column. While the Force SQL_WCHAR Support option is still available in the 9.2.0.2.0 ODBC Driver, it is no longer required for Unicode support."
    Justin

  • Poor performance getting lastModified()

    Hi,
    I am having a problem when working on a set of (many) File objects. When i create a method for a plain output - to System.out f.e. - the performance is quiet satisfying (some thousand per sec.).
    for comparison reasons i need the lastModified() data. replacing the
         System.out.println(myFile[counter].getName());with
         System.out.println(myFile[counter].lastModified());was shocking. Performance went down to around 30 files per second - which is quiet unusable.
    I'm using J2SDK 1.4.2_03, XP and some Ghz Athlon.
    i was searching the web for days but found nothing about the subject. Is the underlying native FileSystem this bad or is my Java broken? Can't beliebe I am the only one affected.
    Are there getLastModified() - setLastModified() JNI implementations ready done somewhere? I'm not able to spend days on JNI just for this two functions.
    Thanks for any comments, solutions and more information
    J.

    I believe that Microsoft never attempted for the fact that it could be reasonable to have an API that gives the file information quickly because the usage pattern for such info at Microsoft (for instance, in Windows Explorer) is:
    - Call FindFirstFile, it returns a handle to a object that FindFirstFile created for listing the directory.
    - Retrieve the complete file information for each file using FindNextFile.
    - Call FindClose to close the handle.
    Doing the same thing in Java means:
    # Calling File.listFiles()
    - Call FindFirstFile
    - Retrieve file name for each file in director using FindNextFile.
    - Call FindClose.
    # For each file in the File[] returned by File.listFiles(), call File.getLastModified()
    - Call FindFirstFile only to get the lastModified information.
    - Call FindClose.
    Microsoft will say "Why Java did not used the handle that FindFirstFile returned, for reading only the file info? FindFirstFile is very slow, but it has a lot of work to do."
    Well... See if opening the file in C++ is quicker than call FindFirstFile. Maybe you could find that it is actually worse.

  • How to Read the Timestamp of a File on Unix from Form?

    If you have a file located on UNIX operating, what is the best way to read the time stamp (the date that file has been created) of that file from Oracle SQL, SQL*plus, or Developer Forms 6i/9i/10g?

    Thanks Robin for the reply! Your suggestion seems to be good!
    However, We found a solution now! I would like to share with you the way we did, in case anyone out there need the solution:
    In SQL*Plus, we created a Java Source below:
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "FileDate"
    AS
    import java.io.File;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    public class FileDate {
    public static String GetDate(String strFilePath) {
    String ReturnValue = null;
    if (strFilePath == null || strFilePath.length()==0)
    // do nothing
    else
    File aFile = new File(strFilePath);
    if (aFile.exists())
    long lngTime = aFile.lastModified();
    Date aDate = new Date(lngTime);
    SimpleDateFormat fmtDate =
    new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
    ReturnValue = fmtDate.format(aDate);
    fmtDate = null;
    aDate = null;
    aFile = null;
    return ReturnValue;
    -- Then we created a wrapper to call the Compiled Java above:
    CREATE or REPLACE FUNCTION FileDate_GetDate(FilePath IN STRING)
    RETURN VARCHAR2 IS
    LANGUAGE JAVA
    NAME 'FileDate.GetDate(java.lang.String) return int';
    -- Then we created a database package:
    -- Package Spec:
    PACKAGE sap_dnld AS
    FUNCTION get_file_date2 (s1 varchar2) RETURN VARCHAR2;
    END sap_dnld;
    -- Package Body:
    PACKAGE BODY sap_dnld AS
    FUNCTION get_file_date2( s1 VARCHAR2 )
    RETURN VARCHAR2 AS LANGUAGE JAVA
    NAME 'FileDate.GetDate(java.lang.String) return int';
    END sap_dnld;
    -- Then we tested the whole thing in SQL*Plus:
    set serveroutput on;
    declare
    x varchar2(2000);
    begin
    x := sap_dnld.get_file_date2;
    dbms_output.put_line(x);
    end;
    -- Then we called the function from the package using a procedure from the form:
    PROCEDURE Find_date IS
    BEGIN
    :control.file_date := sap_dnld.get_file_date2('directory1/subdirectory/filename.txt');
    END;

  • Fully qualified filename (including path)

    I have a sample program I'm playing with to learn a bit about JAVA. In the code below I have variables named 'file1' and 'file2' which are defined with a filenames 'file1.txt' and file2.txt respectively.
    So when the program executes it looks for these files in the current directory. However, if I want to change these values to 'c:\file1.txt' and 'c:\ttmsapps\file2.txt' then I can't compile the program.
    Would someone be able to show me in the code below how to specify a fully qualified filename? I'd certainly appreciate seeing the example.
    import java.io.File;
    import java.lang.Object;
    import java.util.Date;
    import java.text.Format;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    public class CompareFileDates {
      public static void main(String[] args) {
        String fileStatus = " ";
        String file1 = "file1.txt";
        String file2 = "file2.txt";
        long date1 = 0;
        long date2 = 0;
        String finalDate1 = null;
        String finalDate2 = null;
        boolean file1Exists = (new File(file1)).exists();
        boolean file2Exists = (new File(file2)).exists();
        if (file1Exists) {
            // Get the timestamp from file 1 and format it
            date1 = (new File(file1)).lastModified();
         Date newDate1 = new Date(date1);
         DateFormat df = new SimpleDateFormat();
         finalDate1 = df.format(newDate1);
        else {
            // File or directory does not exist
            fileStatus = file1 + " does not exist.  ";
    ...more

    Awesome. I'm getting very close.
    However, in building the variable 'file1' on the Windows-side I will need to be specific to the which Drive Letter the file exists on...for instance I may need to specify 'C:\' as part of the creation of the 'file1' variable. This is because the java program will be executed by people on the File Server on the K: drive, yet I want the program to specify a file on their C: drive. If I do this then the program wouldn't run on UNIX, right? Because UNIX doesn't have Drive Letters (e.g. C:, K:).
    In this case would I have to hard code the Drive Letter for Windows and then edit and remove the Drive Letter before running the program on UNIX?
    Here's my program so far which will run on Windows or UNIX, but it doesn't have the Drive Letter differences required on Windows so the program would have to be executed by the user on the same Drive Letter as the file I'm specifying.
    import java.io.File;
    import java.lang.Object;
    import java.util.Date;
    import java.text.Format;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    public class CompareFileDates {
      public static void main(String[] args) {
        String file1 = File.separator + "exfc" + File.separator + "its" + File.separator + "file1.txt";
        System.out.println(file1);
    }The output on Windows:
    K:\COMMON\ITS\STEVEB\java\CompareFileDates>java CompareFileDates
    \exfc\its\file1.txtThe output on UNIX:
    /data/users/ssbuechl/java/CompareFileDates >java CompareFileDates
    /exfc/its/file1.txt

  • Why exp fail and what other method I should use

    Hi Everybody,
    I plan to "copy" data from a table partition of a transactional database to a remote historical database table,both of the source and destination tables are partitioned in the same way
    In the source 9i database, I do the exp using below command
    exp reporter/password file=rs_p20101128.dmp tables=(reporter.reporter_status:p_20101128)
    About to export specified tables via Conventional Path ...
    +. . exporting table REPORTER_STATUS+
    +. . exporting partition P_20101128 212932 rows exported+
    EXP-00091: Exporting questionable statistics.
    EXP-00091: Exporting questionable statistics.
    EXP-00091: Exporting questionable statistics.
    EXP-00091: Exporting questionable statistics.
    EXP-00091: Exporting questionable statistics.
    EXP-00091: Exporting questionable statistics.
    Export terminated successfully with warnings.
    In the remote 10g databse, I do the imp using below command but fail
    imp reporter/password01   FROMUSER=reporter file=/tmp/rs_p20101128.dmp tables=(REPORTER_STATUS:P_20101128)
    Import: Release 10.2.0.2.0 - Production on Mon Nov 29 17:52:31 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    Export file created by EXPORT:V09.02.00 via conventional path
    import done in US7ASCII character set and AL16UTF16 NCHAR character set
    import server uses AL32UTF8 character set (possible charset conversion)
    +. importing REPORTER's objects into REPORTER+
    +. importing REPORTER's objects into REPORTER+
    IMP-00015: following statement failed because the object already exists:
    +"CREATE TABLE "REPORTER_STATUS" ("IDENTIFIER" VARCHAR2(255), "SERIAL" NUMBER"+
    +"(16, 0), "NODE" VARCHAR2(64), "NODEALIAS" VARCHAR2(255), "MANAGER" VARCHAR2"+
    +"(64), "AGENT" VARCHAR2(64), "ALERTGROUP" VARCHAR2(64), "ALERTKEY" VARCHAR2("+
    +"255), "SEVERITY" NUMBER(16, 0), "SUMMARY" VARCHAR2(255), "FIRSTOCCURRENCE" "+
    +......+
    +"0 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 10485760 FREELISTS 1 FREELIST GRO"+
    +"UPS 1) TABLESPACE "REPORTER" LOGGING NOCOMPRESS )"+
    IMP-00055: Warning: partition or subpartition "REPORTER_STATUS":"P_20101128" not found in export file
    Import terminated successfully with warnings.
    Any suggestion to make the things work?
    Clay

    thanks for all your suggestions but the problem persists, pls have a look at below command and output captures.
    In source 9i database, I do export using below command and got below output:
    +reporter@xxam[tmp] 554 %scp rs_p20101128.dmp [email protected]:/tmp/. Password:+
    +HGCP@hgcam02[tmp] 555 %exp reporter/passwdx01 file=rs_p20101127.dmp tables=(reporter.reporter_status:P_20101127) statistics=none INDEXES=N TRIGGERS=N CONSTRAINTS=N consistent=y+
    Export: Release 9.2.0.6.0 - Production on Mon Nov 29 18:18:36 2010
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to: Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.6.0 - Production
    Export done in US7ASCII character set and AL16UTF16 NCHAR character set
    server uses WE8ISO8859P1 character set (possible charset conversion)
    Note: indexes on tables will not be exported
    Note: constraints on tables will not be exported
    About to export specified tables via Conventional Path ...
    +. . exporting table REPORTER_STATUS+
    +. . exporting partition P_20101127 195127 rows exported+
    Export terminated successfully without warnings.
    =================================
    In destination 10g database, I do import using below command and got below output:
    bash-3.00$ imp reporter/passwd0001   FROMUSER=REPORTER TOUSER=REPORTER file=/tmp/rs_p20101127.dmp tables=(REPORTER_STATUS:P_20101127)
    Import: Release 10.2.0.2.0 - Production on Mon Nov 29 18:23:54 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    Export file created by EXPORT:V09.02.00 via conventional path
    import done in US7ASCII character set and AL16UTF16 NCHAR character set
    import server uses AL32UTF8 character set (possible charset conversion)
    +. importing REPORTER's objects into REPORTER+
    IMP-00015: following statement failed because the object already exists:
    +"CREATE TABLE "REPORTER_STATUS" ("IDENTIFIER" VARCHAR2(255), "SERIAL" NUMBER"+
    +"(16, 0), "NODE" VARCHAR2(64), "NODEALIAS" VARCHAR2(255), "MANAGER" VARCHAR2"+
    +"(64), "AGENT" VARCHAR2(64), "ALERTGROUP" VARCHAR2(64), "ALERTKEY" VARCHAR2("+
    +"255), "SEVERITY" NUMBER(16, 0), "SUMMARY" VARCHAR2(255), "FIRSTOCCURRENCE" "+
    +"DATE NOT NULL ENABLE, "LASTOCCURRENCE" DATE, "LASTMODIFIED" DATE, "INTERNAL"+
    +"LAST" DATE, "POLL" NUMBER(16, 0), "TYPE" NUMBER(16, 0), "TALLY" NUMBER(16, "+
    +"0), "CLASS" NUMBER(16, 0), "GRADE" NUMBER(16, 0), "LOCATION" VARCHAR2(64), "+
    +""OWNERUID" NUMBER(16, 0), "OWNERGID" NUMBER(16, 0), "ACKNOWLEDGED" NUMBER(1"+
    +.................+
    +"0 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 10485760 FREELISTS 1 FREELIST GRO"+
    +"UPS 1) TABLESPACE "REPORTER" LOGGING NOCOMPRESS )"+
    Import terminated successfully with warnings.

  • How to synchronize a local file with the remote copy.

    I have a local file (file.txt) inside the directory of my java application and also a copy in a remote machine. Every time I start the application I want to check if the remote copy has been updated and if yes, synchronize the local copy. If you have done this before, please let me know. Thank you very much!

    you could make a URL connection to that file, check it's lastModified date, and download if you need to update

Maybe you are looking for