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: Summary: I/O

This needs a lot of work!!!!!!!!!!! Related classes: File, BufferedReader, ....
System Methods
Some System methods are relevant to I/O
String System.getProperty("user.dir") Returns the path to the current directory (ie, the value of ".").

File Methods

These are some of the most common File methods. In all of these prototypes, i and j are int, s and t are Strings, and c is a char.
booleanf.exists() true if file exists.
booleanf.isFile() true if its a file.
booleanf.isDirectory() true if its a directory.
String f.getName() returns name of file/directory.
String f.getPath() returns path of file/directory.
File[] File.listRoots() [Java 2] list of file system roots, eg, A:, C:, ....

BufferedReader/BufferedWriter Methods

java.io.BufferedReader and java.io.BufferedWriter are used to read/write Strings from/to text files.
Constructors -- see example below
BufferedReader Methods
Stringbr.readLine() Returns next input line without newline char(s) or null if no more input. May throw IOException.
Stringbr.close() Should close when finished reading.
BufferedWriter Methods
voidbw.writeLine(s) Writes s to file without newline char(s). May throw IOException.
Stringbw.close() MUST close when finished writing.

Example

// Example reads from from one file and writes to another.
// Assume inFile and outFile are Strings with path/file names.
try { 
    BufferedReader bufReader = new BufferedReader(new FileReader(inFile)); 
    BufferedWriter bufWriter = new BufferedWriter(new FileWriter(outFile)); 

    String line = null; 
    while ((line=bufReader.readLine()) != null){ 
        bufWriter.write(line); 
        bufWriter.newLine();   // adds newline character(s)
    } 

    bufReader.close(); 
    bufWriter.close(); 

} catch (IOException e) { 
    System.err.println(e); 
    System.exit(1); 
}

Copyright 1999 Fred Swartz Last update: 2000-02-30
Facing Programming Problem?
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:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

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.

  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.