import java.io.*;
class PenDrive implements Runnable
{
public PenDrive()
{
}
}
public class FindDrive
{
public static void main(String[] RK)
{
String[] letters = new String[]{ "A", "B", "C", "D", "E", "F", "G", "H", "I"};
File[] drives = new File[letters.length];
boolean[] isDrive = new boolean[letters.length];
int totFiles=0,totDirs=0;
// init the file objects and the initial drive state
for ( int i = 0; i < letters.length; ++i )
{
drives[i] = new File(letters[i]+":/");
isDrive[i] = drives[i].canRead();
}
System.out.println("FindDrive: waiting for devices...");
while(true)
{
// check each drive
for ( int i = 0; i < letters.length; ++i )
{
boolean pluggedIn = drives[i].canRead();
// if the state has changed output a message
if ( pluggedIn != isDrive[i] )
{
if ( pluggedIn )
{
String path=letters[i]+"://";
File files=new File(path);
String allFiles[]=files.list();
for(int k=0; k
File f=new File(path+"/"+allFiles[k]);
if(f.isDirectory())
{
totDirs++;
System.out.println("Directory :"+allFiles[k]);
}
else
{
totFiles++;
System.out.println("File :"+allFiles[k]);
}
}
System.out.println("Total Directories and Files :"+allFiles.length);
System.out.println("Total Directories :"+allFiles.length);
System.out.println("Total Files :"+allFiles.length);
}
else
{
System.out.println("Drive "+letters[i]+" has been unplugged");
}
isDrive[i] = pluggedIn;
}
}
try
{
Thread.sleep(100);
}
catch (InterruptedException e)
{ }
}
}
}
Thank You.
there are some errors in the program :(
ReplyDeletewhat is the errors ?? can you send me ?
Deletefor(int k=0; k {
ReplyDeletecheck this.
It isn't written in proper way.....
Please correct this.....
Thank you.....
this program is bullshit..
ReplyDeleteThis program does run, but whenever I eject my pendrive, and insert it again, it doesn't show directories.
ReplyDeletePlease update that query.
And share it again. Thanks.