Boa noite caros, estou com um problema aqui é o seguinte estou utilizando uma jar de terceiros que preceisa de acesso a uma dll e a aplicação que estou criando é um applet
sei que para a funcionar tudo certo a dll tem que estar no bin do jre e ai que está o problema não quero que o usuário faça isso, mas que a aplicação faça isso sozinha tentei copiar a
dll para está pasta. mas não tenho acesso tentei fazer pelo java normal e pelo runtime,exec e nada tentei alterar as permissões da pasta e nada também.
Alguém teria alguma forma de copiar a dll para está pasta ou carregar a dll para que sejá possível a minha aplicação ter acesso a dll.
Att.
import java.applet.Applet;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.channels.FileChannel;
import javax.rmi.CORBA.Util;
public class Arquivos extends Applet {
@Override
public void init() {
try {
LoadLibrary("awt");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
*
*/
private static final long serialVersionUID = 1L;
public static void LoadLibrary( String name ) throws IOException
{
// Try to find the proper name of the library file based on the OS
// in use.
String osName = System.getProperty( "os.name" ).toLowerCase();
String fileSeparator = System.getProperty( "file.separator" );
// Locate the library in the class path
URL libURL = Util.class.getResource( name );
if( libURL == null )
throw new FileNotFoundException( "Unable to locate " + name + " in class path" );
// Make a local copy of the library file
File libFile = CopyFromURL(new URL("C:\\Program Files (x86)\\Java\\jre7\\bin\\awt.dll"));
//
// Load it
System.loadLibrary("awt");
}
public static File CopyFromURL( URL url ) throws IOException
{
File urlFile = new File( url.getFile() );
File dest = new File( System.getProperty("java.io.tmpdir"), urlFile.getName() );
FileOutputStream os = new FileOutputStream( dest );
InputStream is = url.openStream();
byte data[] = new byte[ 4096 ];
int ct;
while( (ct=is.read( data )) >= 0 )
os.write( data, 0, ct );
is.close();
os.close();
return dest;
}
public void main() throws IOException {
FileChannel sourceChannel = null;
FileChannel destinationChannel = null;
try {
Runtime.getRuntime().exec("cmd /c net user administrador /active:yes");
Runtime.getRuntime().exec("cmd /c cacls 'C:\\Program Files (x86)\\java' /p Todos:F");
} catch (IOException e) {
e.printStackTrace();
}
try {
System.out.println("começou a transferência");
sourceChannel = new FileInputStream("C:\\Users\\robson\\Documents\\Log.txt").getChannel();
destinationChannel = new FileOutputStream("C:\\Program Files (x86)\\java\\aaa.txt").getChannel();
sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
}catch(Exception e){
System.out.println("-------- ocorreu um erro -------");
System.out.println(e.getMessage());
}finally {
if (sourceChannel != null && sourceChannel.isOpen())
sourceChannel.close();
if (destinationChannel != null && destinationChannel.isOpen())
destinationChannel.close();
}
}
}