我正在开发一个小程序。小程序被烧毁,一些代码完美运行。我使用以下方法在本地保存从远程站点读取的库:
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
try{
URL url = new URL(getCodeBase(), "./dyn_libs/libusb4java.so");
byte[] buffer = new byte[1024];
InputStream is = url.openStream();
String tmpDir = System.getProperty("java.io.tmpdir");
String fileSeparator = System.getProperty("file.separator");
String userName = System.getProperty("user.name");
FileOutputStream os = new FileOutputStream(tmpDir+fileSeparator+"libusb4java.so");
int nRead=0;
int total=0;
while((nRead = is.read(buffer))!= -1){
os.write(buffer);
total+=nRead;
}
is.close();
os.close();
}catch (Exception e){
PrintWriter writer = null;
try {
writer = new PrintWriter(new FileWriter("/tmp/salida.txt", true));
writer.println("error en el catch"+e.getMessage());
writer.close();
return "error en el access controller : "+e.getMessage();
} catch (Exception ex) {
Logger.getLogger(fpc_01.class.getName()).log(Level.SEVERE, null, ex);
} finally {
writer.close();
}
}
return null;
}
});
但是当我想加载本机库时,什么也没有发生,我的意思是,没有错误,小程序只是停止运行。我加载本机库:
try {
String resultado= AccessController.doPrivileged(new PrivilegedAction<String>() {
@Override
public String run() {
PrintWriter writer = null;
try {
writer = new PrintWriter(new FileWriter("/tmp/salida.txt", true));
// privileged code goes here, for example:
System.load("/tmp/libusb4java.so");
writer.println("exito");
writer.close();
return "exito"; // nothing to return
}
catch (Exception e)
{
writer.println("error en el catch"+e.getMessage());
writer.close();
return "no puede cargar biblioteca";
}
}
});
}
catch (Exception e)
{
PrintWriter writer;
writer = new PrintWriter(new FileWriter("/tmp/salida.txt", true));
writer.println("error en el catch"+e.getMessage());
writer.close();
return "problema al cargar";
}
欢迎任何线索。TIA 亚历杭德罗