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