Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8156657

Directory and file names ending with spaces are not supported by java.io.File

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 9
    • core-libs
    • None
    • generic
    • windows

      FULL PRODUCT VERSION :
      JDK 1.9.0 b116

      ADDITIONAL OS VERSION INFORMATION :
      64-bit MS Windows 7 OS

      A DESCRIPTION OF THE PROBLEM :
      The method "java.io.File.exists()" called on "java.io.File" object constructed from the absolute path to existing in the file system directory or file, whose name ends with space characters, for example "Directory1 ", "File1 ", "File2.txt ", always returns "false" value.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile the specified below test case.
      2. Create in the file system a directory or a file, whose name ends with any number of space characters.
      3. Run the compiled test case with a tested JDK and specify the absolute path to the created in the step #2 directory or file as the argument for the test case. For example:

      "C:\Program Files (x86)\Java\jre-9\bin\java" FileNameEndingWithSpacesIsNotSupported "C:\Users\TestUser\AppData\Local\Temp\Directory1 "

      ---------- BEGIN SOURCE ----------
      import java.io.File;

      public class FileNameEndingWithSpacesIsNotSupported {
          public static void main(String[] args) {
              if (args.length > 0) {
                  File file = new File(args[0]);
                  System.out.println(String.format("File '%s' exists()='%b'", file, file.exists()));
              }
          }
      }
      ---------- END SOURCE ----------

            igerasim Ivan Gerasimov
            alitvinov Anton Litvinov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: