Like the person above me said, you can list the roots of your USB directory. After you list the roots, you can find the USB drive manually then write the File object from your USB drive to a File using FileOutputStreams and then just compare that File object later to your drive. Or you can make a unique file name in your USB drive and use
File[] roots = File.listRoots();for(int i = 0; i < roots.length; i++){
File[] filesInRoot = File.listRoots()[i].listFiles();
for(int j = 0; j < filesInRoot.length; j++){
if(filesInRoot[j].getName().equals(yourUniqueFileName))
executeYourCode();
}
}
Ask any questions if you need it! This is a very interesting problem so if you need help with the code, chat me!