0

I have spent two days trying to get this to work. J: is a mapped network drive.

import java.io.File;

File file = new File("J:\\data\\newpasload\\savedir\\");
File[] attachedFiles=file.listFiles();
if (attachedFiles==null) {
    System.out.println("Failed to read j: drive");
} else {
    System.out.println("Number of files = "+attachedFiles.length);
}

The executable jar file works fine when run directly, showing me the number of files in the directory. However I want the executable jar file to run as a scheduled task. When I run it as such the attachedFiles becomes null.

azro
  • 53,056
  • 7
  • 34
  • 70
Tony Wolff
  • 732
  • 1
  • 10
  • 23

1 Answers1

0

According documentation listFiles() returns:

An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs

So you should check path or task permissions. As a variant you can run your java application as a daemon.

Vladislav Kysliy
  • 3,488
  • 3
  • 32
  • 44