Re: byte[ ] of J/Link
- To: mathgroup at smc.vnet.net
- Subject: [mg30437] Re: byte[ ] of J/Link
- From: tgayley at wolfram.com (Todd Gayley)
- Date: Sat, 18 Aug 2001 04:05:00 -0400 (EDT)
- Organization: Wolfram Research, Inc.
- References: <email@example.com>
- Sender: owner-wri-mathgroup at wolfram.com
On Fri, 17 Aug 2001 07:30:19 +0000 (UTC), "Junzo Sato" <jsato at fc.kuh.kumamoto-u.ac.jp>
>I'm trying to create byte with specified length from Mathematica.
>How to implement the following Java code in Mathematica?
>byte data = null;
>RandomAccessFile rf = null;
> rf=new RandomAccessFile("myfile.data","r");
> data=new byte[(int)rf.length()];
There is code very similar to yours in the GetURL example in JLink/Examples/Part1, and the
code is discussed in section 1.3.4 of the J/Link User Guide (Part 1/Example
Programs/Reading a URL). People who want a fuller explanation for this array trick can
read that section.
The actual Java class name of a 1-D array of bytes is "[B", so this is what you specify as
the class name to JavaNew:
data = JavaNew["[B", rf@length]
The cryptic class names for arrays of primitive types can be found in the Java
documentation (I know they are listed somewhere in the JNI docs), but you can also write a
simple Java program to get them. For example:
byte foo = new byte;
System.out.println(foo.getClass().getName()); // This prints out "[B"
Prev by Date:
Re: How to do a simple loop?
Next by Date:
Re: Mathlink and BorlandC++
Previous by thread:
byte[ ] of J/Link
Next by thread:
Optica - freeforms with xyz-points