Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Working With File 
 

In the previous chapter, we learned how to work with the streams.

 

Working With File

                         

In the previous chapter, we learned how to work with the streams. which provide a simple model for reading and writing data. However, streams don't support all the operations that are common with a disk file. In lesson, we will learn how to work with a file using the non-stream file I/O.

The File class deals with the machine dependent files in a machine-independent manner i.e. it is easier to write platform-independent code that examines and manipulates files using the File class. This class is available in the java.lang package.
The java.io.File is the central class that works with files and directories. The instance of this class represents the name of a file or directory on the host file system. 

When a File object is created, the system doesn't check to the existence of a corresponding file/directory. If the file exist, a program can examine its attributes and perform various operations on the file, such as renaming it, deleting it, reading from or writing to it.

The constructors of the File class are shown in the table:

 Constructor  Description
 File(path)  Create File object for default directory (usually where program is located).
 File(dirpath,fname)  Create File object for directory path given as string.
 File(dir, fname)  Create File object for directory.

Thus the statement can be written as:

File f = new File("<filename>");

The methods that are used with the file object to get the attribute of a corresponding file shown in the table.

 Method  Description
 f.exists()  Returns true if file exists.
 f.isFile()  Returns true if this is a normal file.
 f.isDirectory()  true if "f" is a directory.
 f.getName()  Returns name of the file or directory.
 f.isHidden()  Returns true if file is hidden.
 f.lastModified()  Returns time of last modification.
 f.length()  Returns number of bytes in file.
 f.getPath()  path name.
 f.delete()  Deletes the file.
 f.renameTo(f2)  Renames f to File f2. Returns true if successful.
 f.createNewFile()  Creates a file and may throw IOException. 

                         

» View all related tutorials
Related Tags: java c exception file ide files data time script directory io copy multiple method get display ip vi exec content

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

I find the materials in this site more useful and easy to understand and I appreciate those who worked for this. I request you to add more examples to make the understanding rigid.The documentation of Turbo C++ gives a rigid insight of everything in an easy manner .And I wish that content makers of this site would take efforts to it.
Offering my service
REYNOLD.P.J

Posted by Reynold P J on Thursday, 12.11.08 @ 02:16am | #82629

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.