Java Not able to create a file in windows shared folder from Linux

Viewed 1150

I am trying to create a file in a shared folder using the below code. I am able to do it when i run this code on windows. But however when i run the same code on linux it is not working.

In liunx it is creating a file named "\192.168.1.102\share\1.pdf" in the folder where i run this java code instead of creating a file 1.pdf in the shared folder "\192.168.1.102\share\".

It seems like while running on Linux the server was not identifying the path as a shared location, Instead it reads that as it's local path.

Are there any other ways to create a file in the shared folder? Could anyone please help me in resolving this?

public class Test {

    public static void main(String args[]) {

        String s1 ="\\\\192.168.1.102\\share";
        try{

            FileOutputStream fos = new FileOutputStream(s1+"\\1.pdf");
            fos.write(("Testing Success").getBytes());
            fos.close();
        }
        catch(Exception e){
            e.printStackTrace();
            System.out.println(e.toString());
        }

        File file = new File(s1);
        System.out.println(file.exists());
    }
}
4 Answers
Related