Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8641083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:26:08+00:00 2026-06-12T11:26:08+00:00

I’m using Oracle Java 7 on Windows 64 bit. When I create a symlink

  • 0

I’m using Oracle Java 7 on Windows 64 bit.

When I create a symlink using Files.createSymbolicLink, I notice this behavior:

  1. If the target is a directory, a “directory symlink” is created.
  2. If the target is a file, a “file symlink” is created.
  3. If the target does not exist, a “file symlink” is created.

The type of the symlink is fixed and never changes, regardless of any changes to its target.

Using Windows’ native mklink command, it is possible to force the link type to be a “directory symlink”. Is it possible to achieve this using the native Java API or some library?

One trivial and ugly way is:

  1. If the target is a directory, just create the link
  2. If the target doesn’t exist, create a new empty target directory, create the link, and delete the directory.
  3. If the target is a file … handle it (move it, apply #2, move it back).

Fugly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:26:11+00:00Added an answer on June 12, 2026 at 11:26 am

    Unfortunately I don’t see a way within the Java APIs to do it.

    I checked the Windows JRE code and it looks like the decision is based on the file attributes themselves:

    try
    {
       WindowsFileAttributes windowsfileattributes = WindowsFileAttributes.get(windowspath2, false);
       if(windowsfileattributes.isDirectory() || windowsfileattributes.isDirectoryLink())
          i |= 1;
    }
    

    The attributes themselves originate from native code, and it looks like there is no way to affect them.

    Clearly you have other options like manually invoking mklink or even manipulating the returned objects using something like PowerMock (which is clearly not meant for this purpose).

    Another dirty option is to create proxys of all the relevant classes: Path, FileSystem and FileSystemProvider.
    The way that it works is that the Path returns a FileSystem which returns a FileSystemProvider – what you need to do is modify how the FileSystemProvider.createSymbolicLink methods behaves.

    The createSymbolicLink method receives a varargs argument which is currently not used – you can pass an argument to it that will indicate your wrapper that it needs to override the way symbolic links are created – and there you go 🙂

    After writing all of this – the only question I have is – why do you need this kind of behavior?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.