javaµ÷ÓÃdllÀý×Ó
×î¼Ñ´ð°¸
1. ±àд·¶ÀýÎĵµ
public class TestNative
{
private native static int Max(int a,int b);
public static void main(String[] args)
{
System.out.println(Max(4,5));
}
static
{
System.loadLibrary("VCdll");
}
}
ÆäÖÐ
LoadLibraryÖеÄDLLÎļþÃû³Æ¿ÉÒÔËæ±ã¶¨.Ö»Òª×öºÃµÄ¶¯Ì¬Á´½Ó¿â¸ÄÃû³ÉÕâ¸ö×Ö·û´®¾Í¿ÉÒÔÁË.¶ønativeº¯ÊýµÄÀ´Ô´¾ÍÊǸö¯Ì¬Á´½Ó¿â.
2. ×öºÃ¸Ã²½×¼±¸ÒÔºó,ÓÃjavac TestNative.javaÉú³ÉTestNative.class. ¼ìÑéÓï·¨.
3. Óï·¨¼ì²éͨ¹ýÒÔºó,ÓÃjavah TestNativeÉú³ÉTestNative.hµÄC++Í·Îļþ.
4. ÓÃVC++6.0´´½¨dllÎļþ:
<1>msdev->new->project->win32 Dynamic-Link Library
<2>Enter project name (e.g. VCdll)
<3>choose "An empty DLL project"->finish
<4>½«3Éú³ÉµÄTestNative.hºÍjdkϵÄjni.hºÍjni_md.h¼ÓÈëµ½¹¤³ÌÖÐÈ¥
<5>Create a c++ file, implements the native method. as follows:
//TestNative.cpp
#include "TestNative.h"
JNIEXPORT jint JNICALL Java_TestNative_Max
(JNIEnv * a, jclass b, jint x, jint y)
{
return x > y ? x : y;
}
±¸×¢:
A ÆäÖеÄjni.hͨ³£ÔÚ jdk\include\ ¿ÉÒÔÏÈ¿½±´µ½VC°²×°Ä¿Â¼ÏµÄincludeĿ¼ÏÂ.Ò»ÀÍÓÀÒÝ,ÒÔºó¿ÉÒÔ·½±ãʹÓÃJNI¼¼Êõ.
B È«²¿µÄÊý¾ÝÀàÐÍÐèÒª¿¼ÂÇJavaºÍVCµÄ½Ó¿ÚÎÊÌâ.ÓÃjint jstring µÈ.
C º¯ÊýÃû³ÆºÍ×Ô¶¯Éú³ÉµÄ.hÎļþÖй涨µÄÒ»ÖÂ.ÃüÃû¹æÔòÊÇ: Java_ʹÓÃÀà_·½·¨Ãû
6. È«±àÒëÒ»ÏÂVC++¹¤³Ì.
Èç¹ûûÓгö´í,Ôò´ËʱÉú³É¶¯Ì¬Á´½Ó¿â³É¹¦.
°Ñ¶¯Ì¬Á´½Ó¿âVCdll.dll¿½±´µ½TestNative.javaËùÔÚµÄĿ¼ÉÏ.
7.ÔËÐÐjava TestNative. OK :-)
Ïà¹ØÎĵµ£º
ÔںܶàJavaÓ¦ÓÃÖÐÐèÒªÔÚ³ÌÐòÖе÷ÓÃJava±àÒëÆ÷À´±àÒëºÍÔËÐС£µ«ÔÚÔçÆڵİ汾ÖУ¨Java SE5¼°ÒÔÇ°°æ±¾£©ÖÐÖ»ÄÜͨ¹ýtools.jarÖеÄcom.sun.tools.javac°üÀ´µ÷ÓÃJava±àÒëÆ÷£¬µ«ÓÉÓÚtools.jar²»ÊDZê×¼µÄJava¿â£¬ÔÚʹÓÃʱ±ØÐëÒªÉèÖÃÕâ¸öjarµÄ·¾¶¡£¶øÔÚJava SE6ÖÐΪÎÒÃÇÌṩÁ˱ê×¼µÄ°üÀ´²Ù×÷Java±àÒëÆ÷£¬Õâ¾ÍÊÇjavax.tools°ü¡£Ê¹ÓÃÕ ......
ÓÐÁ½ÖÖ·½·¨£º
·½·¨Ò»£ºÓÃjava.util.DateÀàÀ´ÊµÏÖ£¬²¢½áºÏjava.text.DateFormatÀàÀ´ÊµÏÖʱ¼äµÄ¸ñʽ»¯£¬¿´ÏÂÃæ´úÂ룺
import java.util.*;
import java.text.*;
//ÒÔÏÂĬÈÏʱ¼äÈÕÆÚÏÔʾ·½Ê½¶¼ÊǺºÓïÓïÑÔ·½Ê½
//Ò»°ãÓïÑÔ¾ÍĬÈϺºÓï¾Í¿ÉÒÔÁË£¬Ê±¼äÈÕÆڵĸñʽĬÈÏΪMEDIUM·ç¸ñ£¬±ÈÈ磺2008-6-16 20:54:53
//ÒÔÏÂÏÔʾµÄÈ ......
´úÂëÈçÏ£º
¡¡¡¡ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º
¡¡¡¡package com.example.pinyin.demo2;
¡¡¡¡import net.sourceforge.pinyin4j.PinyinHelper;
¡¡¡¡import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
¡¡¡¡import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
¡¡¡¡import net.sourceforge.pinyin4j.form ......
package fileIo;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
public&nb ......
File f=new File("DerectoryName");
String []results=f.list();
import java.io.*;
¡¡¡¡public class listFile
¡¡¡¡{ &nb ......