我有一个C应用程序。该应用程序写入和读取一些I / O端口地址。
我认为Java本身无法访问低级I / O地址。我是对的吗?
以下是C ++应用程序的示例:
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <sys/io.h>
int main(int argc, char *argv[])
{
cout << "Refresh watchdog program" << endl;
outb(0x87,0x2E); //Extended Function Mode
outb(0x30,0x2E); //Set Watch Dog Timer Activate
outb(0x01,0x2F);
int reg = inb(0x2f);
outb(reg|0x08, 0x2f);
}
我怎样才能在Java中做同样的事情?
答案 0 :(得分:3)
我认为sun.misc.Unsafe可能会帮助你。它有void putAddress(long address, long value)
等方法可能适合您的需要。说实话,我还没有做过这个,但你可以从
http://mydailyjava.blogspot.co.uk/2013/12/sunmiscunsafe.html
http://mishadoff.github.io/blog/java-magic-part-4-sun-dot-misc-dot-unsafe/
http://highlyscalable.wordpress.com/2012/02/02/direct-memory-access-in-java/
可以在
上找到一个小样本程序http://robaustin.wikidot.com/how-to-write-to-direct-memory-locations-in-java