SORU
22 Mart 2013, Cuma


Nasıl eğer bir klasör olup olmadığını kontrol etmek için

Yeni Java 7 IO özellikleri ile biraz, aslında bir klasörün tüm xml dosyalarını almaya çalışıyor ben oynuyorum. Ama bu klasörü nasıl eğer klasörü yeni IO ile varsa kontrol edebilir miyim? yoksa bir istisna atar

public UpdateHandler(String release) {
    log.info("searching for configuration files in folder "   release);
    Path releaseFolder = Paths.get(release);
    try(DirectoryStream<Path> stream = Files.newDirectoryStream(releaseFolder, "*.xml")){

        for (Path entry: stream){
            log.info("working on file "   entry.getFileName());
        }
    }
    catch (IOException e){
        log.error("error while retrieving update configuration files "   e.getMessage());
    }


}

CEVAP
22 Mart 2013, Cuma


java.nio.file.Files kullanarak:

Path path = ...;

if (Files.exists(path)) {
    // ...
}

İsteğe bağlı olarak bu yöntem iletebilirsiniz LinkOption değerler:

if (Files.exists(path, LinkOption.NOFOLLOW_LINKS)) {

Ayrıca bir yöntem notExists)

if (Files.notExists(path)) {

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • CodingMadeEasy

    CodingMadeEa

    25 EYLÜL 2010
  • L- Crysis

    L- Crysis

    30 Aralık 2011
  • MndsgnVEVO

    MndsgnVEVO

    26 Kasım 2013