jna 缓存文件生成目录
时间: 2023-09-08 19:13:55 浏览: 170
JNA是Java Native Access的缩写,是一个用于在Java中调用本地代码(如C、C++等)的库。JNA在运行时会生成一些缓存文件,用于提高程序的性能。
这些缓存文件会被存储在操作系统的缓存目录中。在Linux系统中,JNA缓存文件的生成目录为`/tmp/jna-<用户名>`,其中`<用户名>`是当前用户的用户名;在Windows系统中,JNA缓存文件的生成目录为`%USERPROFILE%\AppData\Local\Temp\jna-<用户名>`。
在以上路径中,`<用户名>`是当前登录用户的用户名。如果您需要查找JNA缓存文件的路径,可以根据以上路径规则进行查找。
相关问题
涉密国产桌面程序 运行jna 缓存文件映射失败
在运行 JNA 时,如果遇到缓存文件映射失败的问题,可能是由于缓存文件的大小超过了系统限制或者缓存文件被损坏了。为了解决这个问题,您可以尝试增加系统缓存文件的大小限制。您可以使用以下命令来设置系统缓存文件的大小限制:
```
sudo sysctl -w vm.max_map_count=<max_number>
```
其中 `<max_number>` 是您要设置的缓存文件的最大数量。如果您想要永久设置这个值,您可以将以下行添加到 `/etc/sysctl.conf` 文件中:
```
vm.max_map_count=<max_number>
```
另外,您还可以尝试删除 JNA 缓存文件,以便重新生成缓存文件。JNA 缓存文件通常位于 `/tmp/jna-<username>` 目录下,您可以尝试删除这个目录并重新运行您的程序。如果问题仍然存在,您可能需要检查您的应用程序代码以查找其他可能导致缓存文件映射失败的问题。
jna 获取文件作者
JNA(Java Native Access)是一个Java库,可以让Java应用程序调用本地的C/C++动态链接库(DLL/SO)。如果要获取文件作者,需要使用Windows API中的GetFileVersionInfo函数和VerQueryValue函数。可以通过JNA调用这些函数来实现。
以下是示例代码:
```java
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.Version;
public class FileVersionInfo {
public static void main(String[] args) {
String fileName = "C:\\Windows\\System32\\notepad.exe";
Version.VS_FIXEDFILEINFO fileInfo = getFileVersionInfo(fileName);
if (fileInfo != null) {
System.out.println("File version: " + fileInfo.dwFileVersionMS + "." + fileInfo.dwFileVersionLS);
System.out.println("Product version: " + fileInfo.dwProductVersionMS + "." + fileInfo.dwProductVersionLS);
String companyName = getStringFileInfo(fileName, "CompanyName");
System.out.println("Company name: " + companyName);
String fileDescription = getStringFileInfo(fileName, "FileDescription");
System.out.println("File description: " + fileDescription);
String fileVersion = getStringFileInfo(fileName, "FileVersion");
System.out.println("File version string: " + fileVersion);
String productName = getStringFileInfo(fileName, "ProductName");
System.out.println("Product name: " + productName);
String originalFilename = getStringFileInfo(fileName, "OriginalFilename");
System.out.println("Original filename: " + originalFilename);
String comments = getStringFileInfo(fileName, "Comments");
System.out.println("Comments: " + comments);
} else {
System.out.println("File version info not found.");
}
}
private static Version.VS_FIXEDFILEINFO getFileVersionInfo(String fileName) {
Version version = Version.INSTANCE;
int handle = version.GetFileVersionInfoSize(fileName, null);
if (handle <= 0) {
return null;
}
byte[] buffer = new byte[handle];
if (!version.GetFileVersionInfo(fileName, 0, handle, buffer)) {
return null;
}
Pointer pointer = new Pointer(0);
int[] length = new int[1];
if (!version.VerQueryValue(buffer, "\\", pointer, length)) {
return null;
}
return new Version.VS_FIXEDFILEINFO(pointer.getByteArray(0, length[0]));
}
private static String getStringFileInfo(String fileName, String key) {
Version version = Version.INSTANCE;
int handle = version.GetFileVersionInfoSize(fileName, null);
if (handle <= 0) {
return null;
}
byte[] buffer = new byte[handle];
if (!version.GetFileVersionInfo(fileName, 0, handle, buffer)) {
return null;
}
Pointer pointer = new Pointer(0);
int[] length = new int[1];
if (!version.VerQueryValue(buffer, "\\StringFileInfo\\040904b0\\" + key, pointer, length)) {
return null;
}
return pointer.getString(0);
}
}
```
其中,`getFileVersionInfo`函数获取文件的版本信息,`getStringFileInfo`函数获取指定键的字符串信息。在`getStringFileInfo`函数中,`040904b0`是代表英语(美国)的语言和地区代码,可以根据需要修改。
注意,该代码只适用于Windows操作系统。如果要在其他操作系统上运行,需要使用不同的API函数。
阅读全文
相关推荐















