title: Java File.setReadable() doesn't work on Windows
body: <p>I have this code and I want to test a function when a not readable file is passed by parameter. The function doesn't matter here, only the fact that File.setReadble(false) seems not working only on Windows.</p>
  
  <p>The <code>File</code> class is obsolete, so how can I guarantee if a file is readable or not independent of platform?</p>
  
  <p>I tested the same code on Linux and Mac, the test worked correctly.</p>
  
  <pre class="lang-java prettyprint-override"><code>    @Test
      public void testReadableFile2() {
          System.out.println("testReadableFile2");
          URL resource = TestClass.class.getResource("/xml/file.xml");
          assertNotNull(resource);
          Path file = null;
          try {
              file = Paths.get(resource.toURI());
          } catch (final URISyntaxException ex) {
              System.out.println("exception: " + ex);
          }
  
          assertNotNull(file);
          assertTrue(Files.exists(file));
  
          // Query file system
          FileStore fileStore = null;
          try {
              fileStore = Files.getFileStore(file);
          } catch (final IOException ex) {
              System.out.println("IOException for get file store: " + ex);
          }
  
          assertNotNull(fileStore);
  
          boolean isReadable = true;
          if (fileStore.supportsFileAttributeView(DosFileAttributeView.class)) {
              boolean hadException = false;
              try {
                  // Set read-only
                  DosFileAttributeView att = Files.getFileAttributeView(file, DosFileAttributeView.class);
                  att.setReadOnly(true);
                  isReadable = !att.readAttributes().isReadOnly();
              } catch (final IOException ex) {
                  System.out.println("IOException for set attribute: " + ex);
                  hadException = true;
              }
              assertFalse(hadException);
  
          } else if (fileStore.supportsFileAttributeView(PosixFileAttributeView.class)) {
              boolean hadException = false;
              try {
                  // Change permissions
                  PosixFileAttributes attrs = Files.readAttributes(file, PosixFileAttributes.class);
                  Set&lt;PosixFilePermission&gt; newPermissions = attrs.permissions();
                  newPermissions.remove(PosixFilePermission.OWNER_READ);
                  newPermissions.remove(PosixFilePermission.OTHERS_READ);
                  newPermissions.remove(PosixFilePermission.GROUP_READ);
  
                  Files.setPosixFilePermissions(file, newPermissions);
  
                  PosixFileAttributeView newAttr = Files.getFileAttributeView(file, PosixFileAttributeView.class);
                  newAttr.setPermissions(newPermissions);
  
                  boolean owner, others, group;
  
                  owner = newAttr.readAttributes().permissions().contains(PosixFilePermission.OWNER_READ);
                  others = newAttr.readAttributes().permissions().contains(PosixFilePermission.OTHERS_READ);
                  group = newAttr.readAttributes().permissions().contains(PosixFilePermission.GROUP_READ);
                  isReadable = !owner &amp;&amp; !others &amp;&amp; !group;
              } catch (final IOException ex) {
                  System.out.println("io exception: " + ex);
                  hadException = true;
              }
              assertFalse(hadException);
          }
  
          assertFalse(isReadable);
  
          assertFalse(Files.isReadable(file)); // assertion failure here
      }
  </code></pre>
  
  <p>I get an asseertion failure on the last line.</p>
  
  <p>Anybody can help me on this problem?</p>