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

Improve RandomAccessFile.length() to handle special files or files opened with special options

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • tbd
    • 6-pool, 7-pool, 8
    • core-libs
    • None

      In current implementation of RamdomAccessFile.java, it seeks to the end of a file to get the file size, which brings different problems to windows and *nix platforms.

      On windows:
      When using FILE_FLAG_NO_BUFFERING to open a file, you cannot, in general, get the file size by doing a zero seek relative to FILE_END. The end of the file may not coincide with a sector boundary and trying to seek to a non-aligned position (even if you are just trying to find out what that position is) is illegal and will fail. The workaround is to use GetFileSizeEx instead.

      On *nix:
      It will throw IOException when checking /proc files. This is the same issue reported in jdk-7132461.

              RandomAccessFile raf = new RandomAccessFile("/proc/cpuinfo", "r");
              System.out.println("RF:" + raf.length());

            Unassigned Unassigned
            dxu Dan Xu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: