I need to identify disks in my program and do not want to store a file on there just for this purpose. Is there a way other than setting cryptic disk names? It would be great if the solution would be platform independent but it ultimately has to run on Windows.
Asked
Active
Viewed 1,688 times
1
-
1Probably duplication of - http://stackoverflow.com/questions/5482947/how-to-get-hard-disk-serial-number-using-java – Adrian Mitev Mar 17 '14 at 12:28
-
@AdrianMitev with Java 7 you don't need that kind of hacks anymore – fge Mar 17 '14 at 12:36
1 Answers
2
Using Java 7 you can do something approaching that:
for (final FileStore store: FileSystems.getDefault().getFileStores())
System.out.println(store.name());
Note: you also have store.type()
, store.toString()
.
The output of these is, of course, system dependent!

fge
- 119,121
- 33
- 254
- 329
-
If I understand you correctly this would be a solution where I need to set unique names to every device (which I meant by cryptic disk names) since this only gives me the name of the device and not some type of uuid. – Schakal_No1 Mar 17 '14 at 12:56
-
This is the essence of it; per system, you are guaranteed that the filestore names will be unique. It this needs to be unique cross system though, you'll have to mix that with some other unique information. – fge Mar 17 '14 at 13:03
-
It does not appear to be unique even on one system for me: If I attach two USB-Drives called "Volume" both will appear as "Volume" which I wanted to avoid. – Schakal_No1 Mar 17 '14 at 13:09
-
-
The context is that I need to backup files from a couple hundred USB sticks (number will increase with time) to fix folders on my system. Those sticks will be handed to the staff of an organization and keeping files for identification on the sticks has been a huge problem in the past due to persons accidentally deleting those files. Thus I need to identify those sticks by some type of uuid unique to every USB stick. toString() changes everytime I put the sticks in in different order. – Schakal_No1 Mar 18 '14 at 10:28
-
-
This is the solution we did before but some members of staff deleted those files which is the reason I wanted to do this without files on the stick. My current solution is to give each stick an unique name, I was just hoping there would be a way to read the uuid of a stick with java on Windows since every stick does already have one in form of the serial number as pointed out by Adrian Mitev. – Schakal_No1 Mar 18 '14 at 11:44