packageunsorted;importjava.io.File;importjava.io.FileOutputStream;importjava.io.InputStream;importjava.io.OutputStream;public classCopyFile {private static String osname = System.getProperties().getProperty("os.name");public static voidcopyfile() {if (osname.contains("Windows")) {
File f= new File("C:/Windows/System32/jnetpcap.dll");if(!f.exists()) {
System.out.println("copy jnetpcap.dll to system32 folder");
InputStream instream= CopyFile.class.getResourceAsStream("/jnetpcap.dll");
OutputStream out= null;try{
out= new FileOutputStream(new File("C/Windows/System32/jnetpcap.dll"));int read = 0;byte[] bytes = new byte[2048];while((read = instream.read(bytes)) != -1) {
out.write(bytes,0, read);
}
out.flush();
instream.close();
out.close();
}catch(Exception e) {
e.printStackTrace();
System.out.println("copy jnetpcap.dll failed");
}
}
}else if(osname.equalsIgnoreCase("Linux")) {
File f= new File("/usr/lib/libjnetpcap.so");if(!f.exists()) {
System.out.println("copy libjnetpcap.so to /usr/lib/ folder");
InputStream instream= CopyFile.class.getResourceAsStream("/libjnetpcap.so");
OutputStream out= null;try{
out= new FileOutputStream(new File("/usr/lib/jnetpcap.so"));int read = 0;byte[] bytes = new byte[2048];while((read = instream.read(bytes)) != -1) {
out.write(bytes,0, read);
}
out.flush();
instream.close();
out.close();
}catch(Exception e) {
e.printStackTrace();
System.out.println("copy jnetpcap.so failed");
}
}
}
}
}