⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.java

📁 I always wanted to play around with JNI. This is my first attempt so I created a utility DLL called
💻 JAVA
字号:
/*	This code is freeware please modify it! Use of	this code is at you own risk.*/public class Test {    // Load the dll that exports functions callable from java    static {System.loadLibrary("TestImp");}        // Imported function declarations	public native void print(String msg);	public native byte[] readFile(String path);	public native int searchFile(String path, byte[] b, int bLength);	public native String[] findFiles(String path, String mask);	public native String[] checkProcess(String processName, boolean killIt, boolean printOutput);	public native int startProcess(String commandLine, String workingDir);	public native boolean waitForFileMask(String directrory, String fileMask);	public native boolean waitForAnyFile(String directrory);		public void Test() {    } 	public static void main(String [] args) {		Test t = new Test();        // Printf example		t.print("->Testing JNI - Hello from c++\n");        // Loading a file as a byte array example		System.out.println("->Dumping file test.java\n" + new String(t.readFile("test.java")));        // Binary search for a byte array example		String tmp = "//System.out.println";		System.out.println("found \'" + tmp + "\' at " + t.searchFile("test.java", tmp.getBytes(), tmp.length()) + "\n\n");        // Directory listing example        System.out.println("Directory listing of C:\\projects\\code\\java\\*.*");        String[] sa = t.findFiles("C:\\projects\\code\\java", "*.*");        if(sa == null) {            System.out.println("No files found");            return;        }        int count = 0;		for(int x = 0; x < sa.length; x++) {            count++;            System.out.println("->" + sa[x]);        }        System.out.println("->Found " + sa.length + " items");        // Process list example        System.out.println("\nchecking for all processes");        String[] psAll = t.checkProcess(" ", false, false);        if(psAll == null) {            System.out.println("Error checking for all processes");            return;        }         for(int x = 0; x < psAll.length; x++) {            System.out.println("->" + psAll[x]);        }        // Checking for a specific process example        System.out.println("\nchecking for \'Explorer.exe\'");        String[] ps = t.checkProcess("Explorer.exe", false, false);        if(ps == null) {            System.out.println("Error checking for \'Explorer.exe\' process");            return;        }         for(int x = 0; x < ps.length; x++) {            System.out.println("->" + ps[x]);        }        // Terminating a process example        System.out.println("\nkilling \'calc.exe\'");        String[] psKill = t.checkProcess("calc.exe", true, false);        if(psKill == null) {            System.out.println("Error killing \'calc.exe\' process");            return;        }        if((psKill[0].compareTo("calc.exe") == 0) && (psKill.length == 1))        {            System.out.println("Killed \'calc.exe\' process");        }        else        {            System.out.println("Error killing \'calc.exe\' process: not found");        }            // Creating a process example        System.out.println("\nStarting up notepad");        int ret = 0;        if((ret = t.startProcess("C:\\WINDOWS\\NOTEPAD.EXE", "c:\\")) == 0) {             System.out.println("Started notepad");        }        else {             System.out.println("Error " + ret + " starting notepad");        }            // Waiting for a file mask example        System.out.println("\nWaiting for a file");        // Block - maybe wait forever!        if(t.waitForFileMask("C:\\temp", "*.txt")) {              System.out.println("Found a file");        }        else {             System.out.println("Error while waiting for a file");        }        // Waiting for any file example        System.out.println("\nWaiting for any file");        // Block - maybe wait forever!        if(t.waitForAnyFile("C:\\temp")) {             System.out.println("Found a file");        }        else {             System.out.println("Error while waiting for a file");        }	}	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -