jdk/src/share/classes/java/io/File.java
changeset 13568 ce5ab758aeb5
parent 11907 c021db66251d
child 14324 3510b4bf90ee
equal deleted inserted replaced
13567:b124faa29aef 13568:ce5ab758aeb5
     1 /*
     1 /*
     2  * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1994, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   709 
   709 
   710     /* -- Attribute accessors -- */
   710     /* -- Attribute accessors -- */
   711 
   711 
   712     /**
   712     /**
   713      * Tests whether the application can read the file denoted by this
   713      * Tests whether the application can read the file denoted by this
   714      * abstract pathname.
   714      * abstract pathname. On some platforms it may be possible to start the
       
   715      * Java virtual machine with special privileges that allow it to read
       
   716      * files that are marked as unreadable. Consequently this method may return
       
   717      * {@code true} even though the file does not have read permissions.
   715      *
   718      *
   716      * @return  <code>true</code> if and only if the file specified by this
   719      * @return  <code>true</code> if and only if the file specified by this
   717      *          abstract pathname exists <em>and</em> can be read by the
   720      *          abstract pathname exists <em>and</em> can be read by the
   718      *          application; <code>false</code> otherwise
   721      *          application; <code>false</code> otherwise
   719      *
   722      *
   730         return fs.checkAccess(this, FileSystem.ACCESS_READ);
   733         return fs.checkAccess(this, FileSystem.ACCESS_READ);
   731     }
   734     }
   732 
   735 
   733     /**
   736     /**
   734      * Tests whether the application can modify the file denoted by this
   737      * Tests whether the application can modify the file denoted by this
   735      * abstract pathname.
   738      * abstract pathname. On some platforms it may be possible to start the
       
   739      * Java virtual machine with special privileges that allow it to modify
       
   740      * files that are marked read-only. Consequently this method may return
       
   741      * {@code true} even though the file is marked read-only.
   736      *
   742      *
   737      * @return  <code>true</code> if and only if the file system actually
   743      * @return  <code>true</code> if and only if the file system actually
   738      *          contains a file denoted by this abstract pathname <em>and</em>
   744      *          contains a file denoted by this abstract pathname <em>and</em>
   739      *          the application is allowed to write to the file;
   745      *          the application is allowed to write to the file;
   740      *          <code>false</code> otherwise.
   746      *          <code>false</code> otherwise.
  1349         return fs.setLastModifiedTime(this, time);
  1355         return fs.setLastModifiedTime(this, time);
  1350     }
  1356     }
  1351 
  1357 
  1352     /**
  1358     /**
  1353      * Marks the file or directory named by this abstract pathname so that
  1359      * Marks the file or directory named by this abstract pathname so that
  1354      * only read operations are allowed.  After invoking this method the file
  1360      * only read operations are allowed. After invoking this method the file
  1355      * or directory is guaranteed not to change until it is either deleted or
  1361      * or directory will not change until it is either deleted or marked
  1356      * marked to allow write access.  Whether or not a read-only file or
  1362      * to allow write access. On some platforms it may be possible to start the
       
  1363      * Java virtual machine with special privileges that allow it to modify
       
  1364      * files that are marked read-only. Whether or not a read-only file or
  1357      * directory may be deleted depends upon the underlying system.
  1365      * directory may be deleted depends upon the underlying system.
  1358      *
  1366      *
  1359      * @return <code>true</code> if and only if the operation succeeded;
  1367      * @return <code>true</code> if and only if the operation succeeded;
  1360      *          <code>false</code> otherwise
  1368      *          <code>false</code> otherwise
  1361      *
  1369      *
  1374         return fs.setReadOnly(this);
  1382         return fs.setReadOnly(this);
  1375     }
  1383     }
  1376 
  1384 
  1377     /**
  1385     /**
  1378      * Sets the owner's or everybody's write permission for this abstract
  1386      * Sets the owner's or everybody's write permission for this abstract
  1379      * pathname.
  1387      * pathname. On some platforms it may be possible to start the Java virtual
       
  1388      * machine with special privileges that allow it to modify files that
       
  1389      * disallow write operations.
  1380      *
  1390      *
  1381      * <p> The {@link java.nio.file.Files} class defines methods that operate on
  1391      * <p> The {@link java.nio.file.Files} class defines methods that operate on
  1382      * file attributes including file permissions. This may be used when finer
  1392      * file attributes including file permissions. This may be used when finer
  1383      * manipulation of file permissions is required.
  1393      * manipulation of file permissions is required.
  1384      *
  1394      *
  1412         return fs.setPermission(this, FileSystem.ACCESS_WRITE, writable, ownerOnly);
  1422         return fs.setPermission(this, FileSystem.ACCESS_WRITE, writable, ownerOnly);
  1413     }
  1423     }
  1414 
  1424 
  1415     /**
  1425     /**
  1416      * A convenience method to set the owner's write permission for this abstract
  1426      * A convenience method to set the owner's write permission for this abstract
  1417      * pathname.
  1427      * pathname. On some platforms it may be possible to start the Java virtual
       
  1428      * machine with special privileges that allow it to modify files that
       
  1429      * disallow write operations.
  1418      *
  1430      *
  1419      * <p> An invocation of this method of the form <tt>file.setWritable(arg)</tt>
  1431      * <p> An invocation of this method of the form <tt>file.setWritable(arg)</tt>
  1420      * behaves in exactly the same way as the invocation
  1432      * behaves in exactly the same way as the invocation
  1421      *
  1433      *
  1422      * <pre>
  1434      * <pre>
  1441         return setWritable(writable, true);
  1453         return setWritable(writable, true);
  1442     }
  1454     }
  1443 
  1455 
  1444     /**
  1456     /**
  1445      * Sets the owner's or everybody's read permission for this abstract
  1457      * Sets the owner's or everybody's read permission for this abstract
  1446      * pathname.
  1458      * pathname. On some platforms it may be possible to start the Java virtual
       
  1459      * machine with special privileges that allow it to read files that are
       
  1460      * marked as unreadable.
  1447      *
  1461      *
  1448      * <p> The {@link java.nio.file.Files} class defines methods that operate on
  1462      * <p> The {@link java.nio.file.Files} class defines methods that operate on
  1449      * file attributes including file permissions. This may be used when finer
  1463      * file attributes including file permissions. This may be used when finer
  1450      * manipulation of file permissions is required.
  1464      * manipulation of file permissions is required.
  1451      *
  1465      *
  1482         return fs.setPermission(this, FileSystem.ACCESS_READ, readable, ownerOnly);
  1496         return fs.setPermission(this, FileSystem.ACCESS_READ, readable, ownerOnly);
  1483     }
  1497     }
  1484 
  1498 
  1485     /**
  1499     /**
  1486      * A convenience method to set the owner's read permission for this abstract
  1500      * A convenience method to set the owner's read permission for this abstract
  1487      * pathname.
  1501      * pathname. On some platforms it may be possible to start the Java virtual
       
  1502      * machine with special privileges that allow it to read files that that are
       
  1503      * marked as unreadable.
  1488      *
  1504      *
  1489      * <p>An invocation of this method of the form <tt>file.setReadable(arg)</tt>
  1505      * <p>An invocation of this method of the form <tt>file.setReadable(arg)</tt>
  1490      * behaves in exactly the same way as the invocation
  1506      * behaves in exactly the same way as the invocation
  1491      *
  1507      *
  1492      * <pre>
  1508      * <pre>
  1514         return setReadable(readable, true);
  1530         return setReadable(readable, true);
  1515     }
  1531     }
  1516 
  1532 
  1517     /**
  1533     /**
  1518      * Sets the owner's or everybody's execute permission for this abstract
  1534      * Sets the owner's or everybody's execute permission for this abstract
  1519      * pathname.
  1535      * pathname. On some platforms it may be possible to start the Java virtual
       
  1536      * machine with special privileges that allow it to execute files that are
       
  1537      * not marked executable.
  1520      *
  1538      *
  1521      * <p> The {@link java.nio.file.Files} class defines methods that operate on
  1539      * <p> The {@link java.nio.file.Files} class defines methods that operate on
  1522      * file attributes including file permissions. This may be used when finer
  1540      * file attributes including file permissions. This may be used when finer
  1523      * manipulation of file permissions is required.
  1541      * manipulation of file permissions is required.
  1524      *
  1542      *
  1554         }
  1572         }
  1555         return fs.setPermission(this, FileSystem.ACCESS_EXECUTE, executable, ownerOnly);
  1573         return fs.setPermission(this, FileSystem.ACCESS_EXECUTE, executable, ownerOnly);
  1556     }
  1574     }
  1557 
  1575 
  1558     /**
  1576     /**
  1559      * A convenience method to set the owner's execute permission for this abstract
  1577      * A convenience method to set the owner's execute permission for this
  1560      * pathname.
  1578      * abstract pathname. On some platforms it may be possible to start the Java
       
  1579      * virtual machine with special privileges that allow it to execute files
       
  1580      * that are not marked executable.
  1561      *
  1581      *
  1562      * <p>An invocation of this method of the form <tt>file.setExcutable(arg)</tt>
  1582      * <p>An invocation of this method of the form <tt>file.setExcutable(arg)</tt>
  1563      * behaves in exactly the same way as the invocation
  1583      * behaves in exactly the same way as the invocation
  1564      *
  1584      *
  1565      * <pre>
  1585      * <pre>
  1587         return setExecutable(executable, true);
  1607         return setExecutable(executable, true);
  1588     }
  1608     }
  1589 
  1609 
  1590     /**
  1610     /**
  1591      * Tests whether the application can execute the file denoted by this
  1611      * Tests whether the application can execute the file denoted by this
  1592      * abstract pathname.
  1612      * abstract pathname. On some platforms it may be possible to start the
       
  1613      * Java virtual machine with special privileges that allow it to execute
       
  1614      * files that are not marked executable. Consequently this method may return
       
  1615      * {@code true} even though the file does not have execute permissions.
  1593      *
  1616      *
  1594      * @return  <code>true</code> if and only if the abstract pathname exists
  1617      * @return  <code>true</code> if and only if the abstract pathname exists
  1595      *          <em>and</em> the application is allowed to execute the file
  1618      *          <em>and</em> the application is allowed to execute the file
  1596      *
  1619      *
  1597      * @throws  SecurityException
  1620      * @throws  SecurityException