Java 调用Native Method 和Library

Java 调用Native Method和Libary,就会丢失Java自己的一些属性,比如夸平台运行,除非你确认必须调用Native Method 和Library,否则尽量别用,我们通常这样用的原因是之前我们写了很多代码,希望重用,或者是因为执行速度的原因我们需要利用Native code去运行特定的功能。

1. 调用Native Method和Library的例子,

public class SimpleFile {
	public static final char separatorChar='>';
	protected String path;
	protected int fd;

	public SimpleFile(String path) {
		// TODO Auto-generated constructor stub
		this.path = path;
	}
	
	public String getFileName()
	{
		int index = path.lastIndexOf(separatorChar);
		return index <0? path: path.substring(index +1);
	}
	
	public String getPath()
	{
		return this.path;
	}

	public native boolean open();
	public native void close();
	public native int read(byte[] buffer, int length);
	public native int write(byte[] buffer, int length);
	// run when the class is loaded first time.
	static {
		System.loadLibrary("Simple"); //simple.dll
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值