Re[7]: net use
От: aefimov Россия
Дата: 03.07.07 05:58
Оценка:
Здравствуйте, alexmix, Вы писали:

A>Плз, горю. а можно код ?я еще совсем новичок.


Как то так. Набросал на коленке, тесты отработали, но реально я этот код не использовал, так что погоняйте еще.
   public static File getShareDirectory(String share) throws IOException {
      if (share == null) {
         throw new IllegalArgumentException("share is null");
      }
      share = share.toLowerCase();
      Process process = ProcessUtil.exec("NET USE");
      try {
         InputStream inputStream = process.getInputStream();
         try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            for (String line = reader.readLine(); line != null; line = reader.readLine()) {
               String s = line.toLowerCase();
               if (s.startsWith("ok")) {
                  int index = s.indexOf(share);
                  if (index != -1) {
                     // This is correct share
                     // Cut device name (between 'OK' and share)
                     String deviceName = line.substring(2, index).trim();
                     if (deviceName.length() == 0) {
                        // Empty device, return share name
                        deviceName = line.substring(index, index + share.length());
                     }
                     File file = new File(deviceName);
                     if (file.exists() && file.isDirectory()) {
                        return file;
                     }
                  }
               }
            }
         } finally {
            inputStream.close();
         }
      } finally {
         process.destroy();
      }
      throw new FileNotFoundException(share);
   }
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.