안녕하세요. 모두 내가 사용하고 있습니다. if (canRead && canWrite && !isFloppy && isDrive)
"C : \"를 찾은 첫 번째 드라이브 만 읽습니다. HDD와 SSD가 있습니다. 어떤 이유에서든 "D : \"에 대한 ssd를 감지하지 못합니까? 감사.드라이브 감지는 하나의 드라이브 만 감지합니까?
package javaapplication3;
import java.io.*;
import javax.swing.filechooser.FileSystemView;
class filler
{
public static void main(String ar[]) throws InterruptedException
{
FileSystemView fsv = FileSystemView.getFileSystemView();
File[] f = File.listRoots();
for (int i = 0; i < f.length; i++) {
String drive = f[i].getPath();
String displayName = fsv.getSystemDisplayName(f[i]);
String type = fsv.getSystemTypeDescription(f[i]);
boolean isDrive = fsv.isDrive(f[i]);
boolean isFloppy = fsv.isFloppyDrive(f[i]);
boolean canRead = f[i].canRead();
boolean canWrite = f[i].canWrite();
//(type.toLowerCase().contains("removable") || type.toLowerCase().contains("rimovibile"))
if (canRead && canWrite && !isFloppy && isDrive) {
try {
File file = new File(drive +"log_22_2112321321312.log");
if (file.createNewFile()){
System.out.println("File is created!");
}
if (file.exists()){
System.out.println("Drive found " + drive);
file.delete();
}
} catch (IOException e) {
e.printStackTrace();
}
}
if (canRead && canWrite && !isFloppy && isDrive &&(type.toLowerCase().contains("removable") || type.toLowerCase().contains("rimovibile"))) {
try {
File file = new File("log_22_2112321321312.log");
if (file.createNewFile()){
System.out.println("File is created!");
}
if (file.exists()){
System.out.println("Drive found " + drive);
file.delete();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
'canRead','canWrite','isFloppy' 및'isDrive'를 어떻게 결정합니까 ?? – MadProgrammer
이들은 그가 만들어야 만하는 변수입니다. 가능한 출처 : http://www.snip2code.com/Snippet/506/Detect-USB-removable-drive-in-Java – collinjsimpson
좋은 소스 찾기 xD 정확한 소스 플러스에서 포스트에 추가했습니다. – Fusion