如何在Windows Vista中创建符号链接? [英] How do I create a symlink in Windows Vista?

查看:73
本文介绍了如何在Windows Vista中创建符号链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在Windows Vista/2008计算机上从Java创建符号链接(软链接)的方法.我很高兴自己需要召集JNI来执行此操作.虽然我对实际的C代码有所帮助.创建链接的合适的系统调用是什么?指向有关此主题的一些好的文档的指针将不胜感激.

I am looking to create symlinks (soft links) from Java on a Windows Vista/ 2008 machine. I'm happy with the idea that I need to call out to the JNI to do this. I am after help on the actual C code though. What is the appropriate system call to create the link? Pointers to some good documentation on this subject would be very much appreciated.

推荐答案

Windows中的符号链接是使用 CreateSymbolicLink API函数,其参数与

Symbolic links in Windows are created using the CreateSymbolicLink API Function, which takes parameters very similar to the command line arguments accepted by the Mklink command line utility.

假设您正确地引用了JNI和Win32 SDK标头,那么您的代码就可以很简单:

Assuming you're correctly referencing the JNI and Win32 SDK headers, your code could thus be as simple as:

JNIEXPORT jboolean JNICALL Java_ClassName_MethodName
    (JNIEnv *env, jstring symLinkName, jstring targetName)
{
    const char *nativeSymLinkName = env->GetStringUTFChars(symLinkName, 0);
    const char *nativeTargetName = env->GetStringUTFChars(targetName, 0);

    jboolean success = (CreateSymbolicLink(nativeSymLinkName, nativeTargetName, 0) != 0);

    env->ReleaseStringUTFChars(symLinkName, nativeSymLinkName);
    env->ReleaseStringUTFChars(targetName, nativeTargetName);

    return success;
}

请注意,这只是我的脑袋,而且我很久没有与JNI打交道了,所以我可能忽略了进行这项工作的一些优点……

Note that this is just off the top of my head, and I haven't dealt with JNI in ages, so I may have overlooked some of the finer points of making this work...

这篇关于如何在Windows Vista中创建符号链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆