2 Replies Latest reply: Sep 11, 2007 7:26 AM by 807605 RSS

    Date / File Reading Issue

      Hi guys,

      It has been a while since I have touched Java, so I know this is a fairly simple task, but can't really think of what mite be the best way to accomplish it.

      Anyway, basically I have an .xml file with a particular piece of information that I want to extract and look at, the basis of the program is to ensure that as we approach our expiration period for our license an email (or something) is sent out to a user to inform them of this.

      While I (for obvious reasons cannot post the full .xml file) here is part of it...

      <LicenseEntry..... expiry="27/4/2008" .../>

      I am looking to extract the date and see if its within a set time, i.e. say 15 days, and if it is to send out an email.

      Now this will be called from a unix shell script, I know how to extract the date line using Unix, so was wondering if it would be better to extract the line first, then pass this and the number of days before the expiration date we wish to monitor into the java program (as oppose to having the java program extract the string)? Would this be the easier option, though I think it mite be nice just to have the java program do it all!

      The next part for me is really how to compare the date, I appreciate this is fairly simple, but till I can get my head back round java i am not sure where mite be the best place to start/way to do this.

      I would have prob done it all in Unix, but date calculations in Unix is not the best! :S

      Thanks for any help.
        • 1. Re: Date / File Reading Issue
          I would have prob done it all in Unix, but date calculations in Unix is not the best!
          Under Unix you might mean native scripting tools inlcuding the classical sh, ksh, csh, zsh, bash command shells and the awk, sed, grep stuff up to newer tools like perl and the like.

          Java is a fully-fledged programming languge which is very much suited to XML extracting and date manipulation.

          At the end you might be able to solve the problem in both ways, and the choice could be dictated by design considerations.
          • 2. Re: Date / File Reading Issue
            I do mean those Unix tools yes, if I was to start using java, I have never done XML parsing etc, I was not even thinking of doing a full XML parse but rather just treating it as a text file and extracting the 'expiry' part, is there any help that I could use a resource for an example of XML parsing? Does it take much to set this up?

            For reference this is my code so far...

            * Main.java
            * Created on 11 September 2007, 10:58
            package licensechecker;

            import java.io.FileInputStream;
            import java.io.FileOutputStream;
            import java.io.InputStreamReader;
            import java.io.OutputStreamWriter;
            import java.util.Date;

            public class Main
            static String licenseDirectory = new String();
            static String licenseFile = new String();

            Date today = new Date();
            Date expiryDate = new Date();

            /** Creates a new instance of Main */
            public Main()
            System.out.println("License Directory is: " + licenseDirectory );
            System.out.println("License File is: " + licenseFile );


            private static void WriteToLogFile( String stringToWrite )
            //Open the output stream



            public static void main(String[] args)
            //Get the input parameters
            licenseDirectory = args[0];
            licenseFile = args[1];

            Main main = new Main();


            Message was edited by: