JAVA判断32位还是64位,调用不同的DLL(转)

源:JAVA判断32位还是64位,调用不同的DLL

通过获取sun.arch.data.model可判断是32还是64的JAVA

将32或者64位的DLL放不同的目录,实现自适应调用DLL

  Properties props = System.getProperties();
  String bits=String.valueOf(props.get("sun.arch.data.model"));  

  String path = IMyNative.class.getResource("/").getPath() + "dll"+bits;
  System.out.println(path);
  // path=path.substring(1,path.length()).replace("/", "\\");
  File file = new File(path + "/MyNative.dll");
  System.out.println(path);
  System.load(path + "/MyNative.dll");
  NativeLibrary.addSearchPath("MyNative.dll", path);


JNA需要以下包:

jna.jar   platform.jar

下载地址:/Files/wasp520/lib.rar

 

如何判断安装的java是32位还是64位

public class JavaArch{
        public static void main(String[] args){
                String arch = System.getProperty("sun.arch.data.model");
                System.out.println("arch:"+arch);
        }
}

 

posted @ 2015-06-08 12:11  酒醉的Tiger  阅读(1512)  评论(0编辑  收藏  举报