How to pass a file (read from Java) most effectively to a native method?

Posted by soc on Stack Overflow See other posts from Stack Overflow or by soc
Published on 2010-04-26T16:25:11Z Indexed on 2010/04/26 22:33 UTC
Read the original article Hit count: 154

Filed under:
|
|
|
|

Hi,

I have approx. 30000 files (1MB each) which I want to put into a native method, which requires just an byte array and the size of it as arguments.

I looked through some examples and benchmarks (like http://nadeausoftware.com/articles/2008/02/java_tip_how_read_files_quickly) but all of them do some other fancy things.

Basically I don't care about the contents of the file, I don't want to access something in that file or the byte array or do anything else with it. I just want to put a file into a native method which accepts an byte array as fast as possible.

At the moment I'm using RandomAccessFile, but that's horribly slow (10MB/s).

Is there anything like

byte[] readTheWholeFile(File file){ ... }

which I could put into

native void fancyCMethod(readTheWholeFile(myFile), myFile.length())

What would you suggest?

© Stack Overflow or respective owner

Related posts about java

Related posts about efficiency