1

Does anyone know of a way to issue commands to a hard drive within Java? Does Java even support this kind of hardware interaction?

For example, if I have a SCSI hard drive that I would like to inquiry, is there a pre-existing Java method to do this, or would I have to write my own?

http://en.wikipedia.org/wiki/SCSI has some general information on SCSI commands in case you aren't familiar.

troyal
  • 2,499
  • 6
  • 25
  • 28

4 Answers4

6

Java doesn't support talking directly to hardware like that. However, you can use JNI to call a C/C++ function from Java that can.

dj_segfault
  • 11,957
  • 4
  • 29
  • 37
  • Can I use other languages with JNI to access the hard drive, or is it limited to C/C++? Alternatively, would it be possible to write a program entirely in C/C++ that is called/run by a Java program? – troyal Dec 24 '08 at 00:24
  • Yes and Yes. I've heard you can use aseambly directly, and yes, you can run a complete program from Java. – OscarRyz Dec 24 '08 at 00:56
2

Three words "JNI or JNA". I strongly recommend taking a look at the latter to see if it suits your situation, instead of just opting for JNI.

Lawrence Dol
  • 63,018
  • 25
  • 139
  • 189
1

No, since Java runs in a "virtual" machine rather than a real one. But it could be used as a bridge as dj mentioned earlier using JNI.

According to Wikipedia JNI can also call assembly directly. JNI could be used to call complete programs written in C or C++

OscarRyz
  • 196,001
  • 113
  • 385
  • 569
  • 1
    If the C/C++ code is a complete program, there's no reason to use JNI; you can just execute the program. JNI is non-trivial to implement, so I wouldn't use it unless I needed to. JNI is used to call *functions* in other languages. I used it at Polaroid to talk to a credit card reader. – dj_segfault Dec 24 '08 at 04:14
0

you need to write the HDD interface code in C/C++ and then call that from Java using JNI

JRomio
  • 2,407
  • 3
  • 26
  • 27