Capture the file creation date

Asked

Viewed 1,061 times

0

I am creating a control panel on jsp to show updates of Excel files of a particular folder on the network.

Problem: I have several SAS programs that are scheduled to update daily, and generate the files in the folder. However, sometimes programming does not perform as expected and the file becomes outdated.

Goal: Identify in the panel everything that is not updated and run the program manually.

The idea I had is to use this formula, but I don’t know how to capture the file date in jsp:

Se dt_arquivo = hoje() campo recebe "Atualizado" senão "Não "Atualizado"
  • Put the code snippet from your jsp view and controller(Servlet), corresponding to the error, would be better to understand your need.

1 answer

0

Creates a method and deposed saves the information in the bank:

public InformacaoArquivo  verificarDataModificacao(String nomeArquivo) throws IOException {
         Path file  =  new File("C:\\text\\"+nomeArquivo).toPath();
         BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);

         InformacaoArquivo info = new InformacaoArquivo(attr.creationTime().toString(), attr.lastAccessTime().toString(), attr.lastModifiedTime().toString() ); 

         System.out.println("hora de criação: " + attr.creationTime());
         System.out.println("último  acesso: " + attr.lastAccessTime());
         System.out.println("última  modifição: " + attr.lastModifiedTime());
        return info;     
    }


public class InformacaoArquivo {

  private String horaCriacao;
  private String ultimoAcesso;
  private String  ultimaModificao;

  public InformacaoArquivo(String horaCriacao, String ultimoAcesso, String ultimaModificao) {
      this.horaCriacao = horaCriacao;
      this.ultimoAcesso = ultimoAcesso;
      this.ultimaModificao = ultimaModificao;
}

You can use in a class and flame in your jsp or if you see yourself wearing a controller can do it as well and pass to jsp

Then you can convert the date to Date and make comparison. all imports have to be from the package java.nio.*;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.