|
|

|  |
Javas File class Javas File class models both files and directories. It manipulates both files and directories as entities. Often the first complication that new Java programmers experience when they begin to write programs that use files is the function of the File class. This class is used to manipulate files and directories, but only as whole entities. You cannot use the File class to read or write data . A File object is created like this: File aFile = new File("filename"); Having created the object we have access to some useful methods, for example: File.canRead(), File.canWrite() Return true if the program is allowed to read or write the file File.createNewFile() As the name suggests, creates a new file with the specified filename File.Delete() Delete the file File.length() Returns the number of bytes in the file The file class is also important because most of the other classes that read and write files will require the filename to be given as a File object, not as a text string. Note: all the Java file handling classes are part of the package java.io, so you probably need to include the line import java.io.*; At the top of your program Back to top 
RITSEC - Global Campus Copyright ?1999 RITSEC- Middlesex University. All rights reserved. webmaster@globalcampus.com.eg |
|