Windows API的Java调用GetShortPathName
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Windows API的Java调用GetShortPathName,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1358字,纯文字阅读大概需要2分钟。
内容图文
![Windows API的Java调用GetShortPathName](/upload/InfoBanner/zyjiaocheng/950/d3721b01d59f4b50af08d9b70f8b900d.jpg)
我感兴趣的函数是GetShortPathName.
http://msdn.microsoft.com/en-us/library/aa364989%28VS.85%29.aspx
我尝试使用此-http://dolf.trieschnigg.nl/eightpointthree/eightpointthree.html
但是在某些情况下,当我使用Java时,它会完全崩溃,因此这不是我的选择.
问题是
我是否必须在C语言中编写代码,制作DLL,然后在JNI / JNA中使用该DLL?
或者,也许我可以以某种方式访问??系统API?
感谢您的评论.
如果您能发布一些代码作为示例,我将不胜感激.
…
我使用JNA找到了答案
import com.sun.jna.Native;
import com.sun.jna.platform.win32.Kernel32;
public class Utils {
public static String GetShortPathName(String path) {
byte[] shortt = new byte[256];
//Call CKernel32 interface to execute GetShortPathNameA method
int a = CKernel32.INSTANCE.GetShortPathNameA(path, shortt, 256);
String shortPath = Native.toString(shortt);
return shortPath;
}
public interface CKernel32 extends Kernel32 {
CKernel32 INSTANCE = (CKernel32) Native.loadLibrary("kernel32", CKernel32.class);
int GetShortPathNameA(String LongName, byte[] ShortName, int BufferCount);
}
}
解决方法:
感谢您的提示.以下是我改进的功能.它使用GetShortPathName的Unicode版本
import com.sun.jna.Native;
import com.sun.jna.platform.win32.Kernel32;
public static String GetShortPathName(String path) {
char[] result = new char[256];
Kernel32.INSTANCE.GetShortPathName(path, result, result.length);
return Native.toString(result);
}
内容总结
以上是互联网集市为您收集整理的Windows API的Java调用GetShortPathName全部内容,希望文章能够帮你解决Windows API的Java调用GetShortPathName所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。