JavaでのUSBサポートはサードパーティのライブラリに限定されています。私はこれらのどれも使用していませんが、JUSBを試すことができます。
USBライブラリで解決策が見つからない場合は、いつでもボギージョブを実行し、Fileオブジェクトあなたはそれを読むことができるかどうかを調べるためにテストします。 USBメモリデバイスが接続されている場合、以前は失敗したドライブ文字が合格するため、新しいデバイスがあることがわかります。もちろん、どのような種類のデバイス(CD/DVDでもかまいません)が分かりません。しかし、私が言ったように、これは理想的な解決策ではありません。 // stackoverflowの:ここで
がポイント
import java.io.*;
/**
* Waits for USB devices to be plugged in/unplugged and outputs a message
*/
public class FindDrive
{
/**
* Application Entry Point
*/
public static void main(String[] args)
{
String[] letters = new String[]{ "A", "B", "C", "D", "E", "F", "G", "H", "I"};
File[] drives = new File[letters.length];
boolean[] isDrive = new boolean[letters.length];
// init the file objects and the initial drive state
for (int i = 0; i < letters.length; ++i)
{
drives[i] = new File(letters[i]+":/");
isDrive[i] = drives[i].canRead();
}
System.out.println("FindDrive: waiting for devices...");
// loop indefinitely
while(true)
{
// check each drive
for (int i = 0; i < letters.length; ++i)
{
boolean pluggedIn = drives[i].canRead();
// if the state has changed output a message
if (pluggedIn != isDrive[i])
{
if (pluggedIn)
System.out.println("Drive "+letters[i]+" has been plugged in");
else
System.out.println("Drive "+letters[i]+" has been unplugged");
isDrive[i] = pluggedIn;
}
}
// wait before looping
try { Thread.sleep(100); }
catch (InterruptedException e) { /* do nothing */ }
}
}
}
を証明するために、最大ノックユーティリティのかわりに#jpos(HTTPSの#javapos(https://stackoverflow.com/tags/javapos/info)を意味するかもしれません。 com/tags/jpos/info)に送信します。 jposは、POSハードウェアを扱わないサーバー側のiso8583フレームワークです。あなたは正しい人からの助けを得ることができるようにあなたのタグを変更したいかもしれません –