2014-02-25 2 views
0

안녕하세요. 모두 내가 사용하고 있습니다. 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(); 
       } 
      } 
     } 
    } 
} 
+0

'canRead','canWrite','isFloppy' 및'isDrive'를 어떻게 결정합니까 ?? – MadProgrammer

+0

이들은 그가 만들어야 만하는 변수입니다. 가능한 출처 : http://www.snip2code.com/Snippet/506/Detect-USB-removable-drive-in-Java – collinjsimpson

+0

좋은 소스 찾기 xD 정확한 소스 플러스에서 포스트에 추가했습니다. – Fusion

답변

0

당신이 File.listRoots()를 사용하고 있습니까 :

죄송 사람은 바르를 포함하는 내 마음을 미끄러? 다음의 출력을 확인하십시오 :

File[] roots = File.listRoots(); 
for (File r : roots) 
    System.out.println(r); 

SSD가 감지되었지만 조건부 기준을 통과하지 않았을 수 있습니다. 조건 내의 코드는 지정된 조건이 충족되는 경우에만 실행됩니다. 조건없이 코드를 실행하여 드라이브가 실제로 인식되지 않는지 또는 논리 오류 또는 기타 볼륨 설정으로 인해 나타나지 않는지 확인하십시오.

+0

Shoudl이 언급했습니다.이 모든것이 있습니다.'FileSystemView fsv = FileSystemView.getFileSystemView(); File [] f = File.listRoots(); for (int i = 0; i Fusion

+0

원래 게시물을 수정하여 코드를 포함시키고 코드 형식을 지정하십시오. 'System.out.println (f [i] .getPath())'를 추가하여 장치를 감지했는지 확인하십시오. 귀하의 조건문은 그것을 생략 할 수 있습니다. – collinjsimpson

관련 문제