Note that there are some explanatory texts on larger screens.

plurals
  1. POJava getting letter of Local Disk Windows
    primarykey
    data
    text
    <pre><code>import java.io.File; import javax.swing.filechooser.FileSystemView; public class DriveLetter{ static String getDriveLetter(){ FileSystemView fsv = FileSystemView.getFileSystemView(); File[] f = File.listRoots(); String letter = null; for(int i = 0; i &lt; f.length; i++){ if((fsv.getSystemDisplayName(f[i]).contains("Disk") || fsv.getSystemDisplayName(f[i]).contains("Local")) &amp;&amp; fsv.isDrive(f[i]) &amp;&amp; !fsv.isFloppyDrive(f[i]) &amp;&amp; f[i].canRead() &amp;&amp; f[i].canWrite() &amp;&amp; f[i].getUsableSpace() &gt; 10000000){ letter = f[i].toString().charAt(0) + ":"; break; } } return letter; } } public class Main{ public static void main(String args []){ if(DriveLetter.getDriveLetter() != null){ new File(DriveLetter.getDriveLetter() + "\\aaa\\bbb").mkdirs(); } else{ JOptionPane.showMessageDialog(null, DriveLetter.getDriveLetter(), "Error",JOptionPane.ERROR_MESSAGE); } } } </code></pre> <p>I wrote a method to get local disk letter. It works fine on my laptop. However it doesn't work on my secondary computer, I get null error as if computer had no primary disk. I gave the code to my friend to test it out and it worked for him, but then I tried it on my brothers computer it did not work again.</p> <p>It seems like my code to get letter of primary disk is very unreliable. Maybe someone could give me some suggestions to make it more reliable?</p> <p>Also I was looking for an easy way to get primary disk letter on windows using java, but I couldn't find anything useful...</p> <p>Maybe someone knows an easier way to get letter of primary disk?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload