Path: blob/master/test/jdk/java/nio/file/DirectoryStream/DriveLetter.java
41153 views
/*1* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 680864725* @summary Checks that a DirectoryStream's iterator returns the expected26* path when opening a directory by specifying only the drive letter.27* @library ..28*/2930import java.nio.file.*;31import java.io.File;32import java.io.IOException;3334public class DriveLetter {3536public static void main(String[] args) throws IOException {37String os = System.getProperty("os.name");38if (!os.startsWith("Windows")) {39System.out.println("This is Windows specific test");40return;41}42String here = System.getProperty("user.dir");43if (here.length() < 2 || here.charAt(1) != ':')44throw new RuntimeException("Unable to determine drive letter");4546// create temporary file in current directory47File tempFile = File.createTempFile("foo", "tmp", new File(here));48try {49// we should expect C:foo.tmp to be returned by iterator50String drive = here.substring(0, 2);51Path expected = Paths.get(drive).resolve(tempFile.getName());5253boolean found = false;54Path dir = Paths.get(drive);55try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {56for (Path file : stream) {57if (file.equals(expected)) {58found = true;59break;60}61}62}63if (!found)64throw new RuntimeException("Temporary file not found???");6566} finally {67tempFile.delete();68}69}70}717273