Sam
Sam

Reputation: 1304

Java createNewFile not working over local network

I have a simple piece of code that creates two directories and two files, and later goes on to populate the directories with more files. When running with files on the local machine (Ubuntu), the code runs as it should.

However, we have a lot of data on a windows server which can be accessed via NFS, so the guys like to cd to a directory on the server and run the code directly from there. This is when the issues occur. The two directories are created fine with .mkdirs() but the .createNewFile( to create the two files throws an IOException with the message No such file or directory and the cause null.

Code below:

private File pDir;
private File dDir;
private File x;
private File headerFile;

creation, sorry about the print statements, I can't run the debugger in Intellij for this

    pDir = new File(outputDirectory + File.separator + "p");
    dDir = new File(outputDirectory + File.separator + "d");
    pDir.mkdirs();
    dDir.mkdirs();
    x = new File(outputDirectory + File.separator + "d_*_1");
    headerFile = new File(outputDirectory + File.separator + "header.Xsam");

    System.out.println(pDir.toString());
    System.out.println("exists? " + pDir.exists());
    System.out.println(dDir.toString());
    System.out.println("exists? " + dDir.exists());
    /*System.out.println(x.toString());
    System.out.println("exists? " + x.exists());
    System.out.println(headerFile.toString());
    System.out.println("exists? " + headerFile.exists());*/

    try {

        x.createNewFile();
        System.out.println("x created");

        headerFile.createNewFile();
        System.out.println("header created");
    }catch(IOException ex){
        System.out.println("error making x or header file: " + ex.getMessage() + " " + ex.getCause());
    }

    System.out.println(pDir.toString());
    System.out.println("exists? " + pDir.exists());
    System.out.println(dDir.toString());
    System.out.println("exists? " + dDir.exists());
    System.out.println(x.toString());
    System.out.println("exists? " + x.exists());
    System.out.println(headerFile.toString());
    System.out.println("exists? " + headerFile.exists());

I've verified that the directories are all created properly. And surely it can't be a permissions issue, since the program carries on to create files in the pDir and dDir using the very same .createNewFile().

Are there any glaring mistakes here, or reasons why it would work with files on the local machine and not over NFS?

Thanks

Upvotes: 0

Views: 135

Answers (1)

IQV
IQV

Reputation: 500

Your problem is the filename you use:

x = new File(outputDirectory + File.separator + "d_*_1");

Windows doesn't accept an asterix "*" in a filename.

Upvotes: 1

Related Questions