Format Drive With Java (Windows )

Format Drive With Java is simple application made to format windows drive.if you are going to make some utility for windows in java or a small project in java then this small application may help you.Source code is free to download.

This project is compiled with netbean 6.9.1. So open it with netbean for quick view.
The trick of format drive in java is exactly the same as in Format drive in C#.
It is totaly based on DOS commands to format a drive. We execute DOS commands to format a drive and provides the necessary parameter like.

  • Drive Letter
  • Speed (Quick,Normal)
  • File System

These parameter provide by this project UI.Below is the special function needs to perform format a drive in java.

First we need the lists of all windows drive so.
Java code to get the list of all windows drive internal or removable.

public void getDname(){
File[] drive =File.listRoots();
for(int i =0;ijComboBox1.insertItemAt(drive[i],i);
catch(Exception e){}


Now all others parameter like format should be quick or normal, file system should be NTFS or FAT32 and what would be the labl of drive after formating.
these all parameter can provided manually through its UI.

For execute format command we will create a batch file which consist of format cammands. Then we will execute this batch file so..

Function to create a batch file consist of format commands

Format Drive With Java

Text Version of the code:
public void createBatch(String Drive,String speed,String type)
// Create file
FileWriter fw = new FileWriter(@"Phoenix.bat");
BufferedWriter bw = new BufferedWriter(fw);
bw.write("Format /y"+" "+Drive+speed+" "+type+" "+ ' '+jText1.getText());
}catch (Exception e){    }


and finally the last to execute that file is the below

Format Drive With Java

Text Version execute batch file contains format commands:

public void executebatch() throws InterruptedException
Process p;
try {
p = Runtime.getRuntime().exec(@'Phoenix.bat');
File f1 = new File(@'Phoenix.bat');
} catch (IOException ex) {


Download source code for free 🙂

[social_lock] [/social_lock]