Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

[an error occurred while processing this directive]

Java Notes

java.io.File

java.io.File is the central class in working with files and directories. Files and directories are both represented by File objects. When a File object is created, the system doesn't test to see if a corresponding file/directory actually exists; you must call exists() to check. See Example - FileTest.java.

File Constructors and Methods

Assume
boolean b;
String s;
String path;     // Relative or absolute path.
String dirpath;  // Relative or absolute path to a directory.
String fname;    // File name
File   f, dir;   // Assume f is a file, dir is a directory.
long   l;
File[] fa;      // Array of File objects.
String[] sa;    // Array of file or directory names.
Constructors
fnew File(path);Create File object for default directory (usually where program is located).
fnew File(dirpath, fname);Create File object for directory path given as string.
fnew File(dir, fname);Create File object for directory.
public static constants
sFile.separator;Default path separator (eg, "/" in Unix, "\" in Windows).
Getting Attributes
bf.exists();true if file exists.
bf.isFile();true if this is a normal file.
bf.isDirectory();true if f is a directory.
sf.getName();name of file or directory.
bf.canRead();true if can read file.
bf.canWrite();true if can write file.
bf.isHidden();true if file is hidden.
lf.lastModified();Time of last modification.
lf.length();Number of bytes in file.
Setting Attributes
 f.setLastModified(t);Sets last modified time to long value t.
bf.setReadOnly();Make file read only. Returns true if successful.
Paths
sf.getPath();path name.
sf.getAbsolutePath();path name (how is it different from above?).
sf.getCanonicalPath();path name. May throw IOException.
sf.toURL();path with "file:" prefix and /'s. Directory paths end with /.
sf.toURI();path with "file:" prefix and /'s. Directory paths end with /.
Creating and deleting files and directories
bf.delete();Deletes the file.
bf.createNewFile();Create file, may throw IOException. true if OK; false if already exists.
bf.renameTo(f2);Renames f to File f2. Returns true if successful.
bf.mkdir();Creates a directory. Returns true if successful.
bf.mkdirs();Creates directory and all dirs in path. Returns true if successful.
Parents and Children
sf.getParent();Name of parent directory.
dirf.getParentFile();File of parent.
sadir.list();Array of file/directory names in dir.
fadir.listFiles();Array of files/directories in dir.
fadir.listFiles(ff);As above after applying java.io.FileFilter ff.

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

0 comments so far (
post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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

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

Copyright © 2007. All rights reserved.