1

Created a Mapped Drive [Z:], which is created against a IBMi share by the command

NET USE Z: \IBMiMachine\PROD /USER:USER1 *******

The drive is created successfully.

Then tried to list all files (e.g. .php/.txt/.html etc) present under the mapped drive, by a simple Java program (using Java 7 IO APIs, and the Java class resides in a runnable jar myjar.jar) by running the command

java -jar myjar.jar Z:

So noticed that java.io.File.isFile() returning the false against the various file:

File: 'Z:\ABC\20100709\Info.php'
isSymbolicLink -- false
isDirectory -- true
exists: true
is file: false
can read: true
can write: true
is hidden: false


File: 'Z:\ZYZ\20100607\intranet\Int.php'
isSymbolicLink -- false
isDirectory -- true
exists: true
is file: false
can read: true
can write: true
is hidden: false

also the java.io.File.isDirectory() also saying those are directories; But those files contents can be seen on command prompt by the command "CAT <file_name>".

My Java Program code like this:

private static int counter = 1;
public static void main(String[] args)
{
    if (Utils.length(args) == 0)
    {
        print("Either passed argument was empty or null: " + Arrays.toString(args));
        return;
    }

    print("Passed argument was: " + Arrays.toString(args));

    doFile(new File(args[0]));
}

private static void doFile(File folder)
{
    if (folder.isDirectory())
    {
        showFileAttributes1(folder);
        showFileAttributes2(folder);

        String files[] = folder.list();
        int length = (files == null) ? 0 : files.length;
        for (int i = 0; i < length; i++)
        {
            doFile(new File(folder, files[i]));
        }
    }
    else if (folder.isFile())
    {
        showFileAttributes1(folder);
        showFileAttributes2(folder);
    }
}

private static void showFileAttributes1(File folder) throws IOException
{
   print("");
   print(" " + counter++ + ". File: '" + folder.getPath() + "' ---------");
    Map<String, Object> fileAttributes = Files.readAttributes(folder.toPath(), "*");
    Iterator<String> iterator = fileAttributes.keySet().iterator();
    while (iterator.hasNext())
    {
        String key = iterator.next();
        print(key + " -- " + fileAttributes.get(key));
    }
}

private static void showFileAttributes2(File file) throws IOException
{
    print("exists: " + file.exists());
    print("is file: " + file.isFile());
    print("can read: " + file.canRead());
    print("can execute: " + file.canExecute());
    print("can write: " + file.canWrite());
    print("is hidden: " + file.isHidden());
    
    Path filePath = Paths.get(file.getAbsolutePath());

    //Is file readable
    boolean isReadable = Files.isReadable(filePath);
    print("Is file readable: " + isReadable);

    //Is file writable
    boolean isWritable = Files.isWritable(filePath);
    print("Is file writable: " + isWritable);

    //Is file executable
    boolean isExecutable = Files.isExecutable(filePath);
    print("Is file executable: " + isExecutable);
}

private static void print(String message)
{
    System.out.println(message);
}

What approach can be taken to overcome of Java problem??

Note: I have the same full access rights on that machine/folder, since by the ROBOCOPY command I am able to copy complete folder structure of mapped drive into my local drive, and then no issue of Java API on that folder then

ROBOCOPY Z: C:\mysource *.php /E /log:log.txt

Kishore_2021
  • 645
  • 12
  • 38
  • 1
    You should provide JDK details, for example is it OpenJDK ? What is the precise version (including minor version) and so on. – Christophe Roussy Jan 07 '21 at 14:18
  • It's a Orcale JDK 1.7 basically, But I also tried in JDK 1.8...but same issue found. – Kishore_2021 Jan 07 '21 at 14:21
  • 1
    Your code does not print "File: '...'", yet you show that line in its output. So the output and the code don't correspond. How do you know you are running the same code that you show us? – k314159 Jan 07 '21 at 14:33
  • 2
    You will get more reliable results using the [java.nio.file](https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/nio/file/package-summary.html) package instead of the ancient java.io.File class. – VGR Jan 07 '21 at 21:45
  • @k314159 ...Update the Java code...check once gain.. – Kishore_2021 Jan 08 '21 at 14:00

0 Answers0