大家好我正在使用if (canRead && canWrite && !isFloppy && isDrive)
它只会读取它找到的第一个驱动器“C:\”,我有一个硬盘和一个SSD,它不会检测到ssd的某些原因“D:\”出于某种原因,任何帮助?感谢。
很抱歉,我们不知所措地包括了这些变种:
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();
}
}
}
}
}
答案 0 :(得分:0)
您使用的是File.listRoots()
吗?检查以下输出:
File[] roots = File.listRoots();
for (File r : roots)
System.out.println(r);
您的SSD可能正在被检测到但未通过条件的标准。条件内的代码只有在满足指定条件时才会执行。在没有条件的情况下运行代码,以查看驱动器是否实际上未被识别,或者是否由于逻辑错误或其他音量设置而未显示。