Java Reference
In-Depth Information
System.out.println("Mean = "
+ (fl oat)total/count);
}
}
Note that there is no structure imposed upon a fi le by Java. It is the programmer's
responsibility to impose any required logical structuring upon the fi le. 'Records' on
the fi le are not physical units determined by Java or the operating system, but logical
units set up and maintained by the programmer. For example, if a fi le is to hold
details of customer accounts, each logical record may comprise the following:
￿
account number;
￿
customer name;
￿
account balance.
It is the programmer's responsibility to ensure that each logical record on the fi le
holds exactly these three fi elds and that they occur in the order specifi ed.
4.2
File Methods
Class File has a large number of methods, the most important of which are shown below.
￿
boolean canRead()
Returns true if fi le is readable and false otherwise.
￿
boolean canWrite( )
Returns true if fi le is writeable and false otherwise.
￿
boolean delete()
Deletes fi le and returns true/false for success/failure.
￿
boolean exists()
Returns true if fi le exists and false otherwise.
￿
String getName()
Returns name of fi le.
￿
boolean isDirectory()
Returns true if object is a directory/folder and false otherwise.
(Note that File objects can refer to ordinary fi les or to directories.)
￿
boolean isFile()
Returns true if object is a fi le and false otherwise.
￿
long length()
Returns length of fi le in bytes.
￿
String[] list()
If object is a directory, array holding names of fi les within directory is returned.
Search WWH ::




Custom Search