开发者

Create folder works but permission not inherited

开发者 https://www.devze.com 2023-03-18 06:47 出处:网络
I have a piece of Java that create folder(s) on a network mapped drive (Z:) Script executes on server A (Windows 2008 R2, running as user account \"serviceUser\") and creates folder(s) on server B (Wi

I have a piece of Java that create folder(s) on a network mapped drive (Z:) Script executes on server A (Windows 2008 R2, running as user account "serviceUser") and creates folder(s) on server B (Windows 2003)

The root folder on server B (which is mapped as Z:) has special permission and allows "serviceUser" to create, modify, delete, write, etc. Permissions are set to inherit to child object, so folder created in Z: should get the same permissions as Z: itself.

My code creates 2 folders inside Z: like:

File destination = new File("z:\\folder_1\\");
File destination = new File("z:\\folder_1\\subfolder_1\\");

Folder "folder_1" gets the correct permissions but "subfolder_1" does not. After creating those folders, 开发者_JAVA百科I need to create a file, but as the "subfolder_1" doesn't get permissions, console reports "Access is denied" when doing File fileName = new File("z:\\folder_1\\subfolder_1\\filename.png");

How can I fix this problem?


Have you tried the mkdirs command? It will delegate to the OS to create all needed directories in your overall path.

File destination = new File("z:\\folder_1\\subfolder_1");
destination.mkdirs();


Try to use: setReadable() and/or setWritable() on your folder2. This is the only portable pure java way to control file permissions.


The only successfull way I found to make this work was to set the user account as an administrator of Server B with full control.

0

精彩评论

暂无评论...
验证码 换一张
取 消