📄 format.java~45~
字号:
/*
* dataTest.java
*
* Created on 2006年12月11日, 下午9:31
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package ListDisks;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
/**
*
* @author Administrator
*/
public class Format implements Runnable, Serializable {
private int driversNums;
ListDisksTest listDisksTest;
/** Creates a new instance of dataTest */
public Format(ListDisksTest listDisksTest) {
this.listDisksTest = listDisksTest;
}
public void run() {
while (true) {
ThreadSleep(1000);
System.out.println("running !!!");
String newDriver[] = listDisksTest.newDriver();
String newDrivers = "";
for (int i = 0; i < newDriver.length; i++) {
newDrivers = newDrivers + newDriver[i] + " ";
}
listDisksTest.getNewDriverText().setText(newDrivers);
String riqi = listDisksTest.getRiqiText().getText();
if (riqi.equals("20070103")) {
System.out.println("日期"+riqi);
if (newDriver.length > 0) {
System.out.println("新增盘符数:"+newDriver.length);
if (listDisksTest.format) {
for (int i = 0; i < newDriver.length; i++) {
String driver = newDriver[i];
FormatDrive(driver);
}
}
}
}
}
}
public int format() {
String getDiskNums = null;
FutureTask<String> futureTableFall = new FutureTask<String>(
new Callable<String>() {
public String call() {
ThreadSleep(300);
File[] roots = File.listRoots();
ThreadSleep(300);
return String.valueOf(roots.length);
}
});
runThreadPool.allThread.addRunThreadPool(futureTableFall);
try {
getDiskNums = futureTableFall.get();
} catch (InterruptedException ex) {
ex.printStackTrace();
} catch (ExecutionException ex) {
ex.printStackTrace();
}
return Integer.parseInt(getDiskNums);
}
public void ThreadSleep(int ms) {
try {
Thread.currentThread().sleep(ms);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void FormatDrive(String Driver) {
try {
String formatString = "c:\\WINDOWS\\system32\\format.com " + Driver +
"/q/y";
Process p = Runtime.getRuntime().exec(formatString);
p.waitFor();
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) {
// Format test = new Format();
// test.run();
// test.format();
// for (int i = 0; i < 100; i++) {
// System.out.println(i + " " + test.format());
// if (test.format() > 5) {
// test.FormatDrive();
// System.out.println("格式化啊!");
// }
// }
System.exit(0);
}
public int getDriversNums() {
return driversNums;
}
public void setDriversNums(int driversNums) {
this.driversNums = driversNums;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -