Using FileWriter and FileReader : Reader « File « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » File » Reader 
9.4.2.Using FileWriter and FileReader
import java.io.*;

public class MainClass {
  public static void main(String [] args) {
    char[] in = new char[50];           
    int size = 0;
    try {
      File file = new File("fileWrite2.txt");
      FileWriter fw = new FileWriter(file);  
      fw.write("howdy\nfolks\n");       
                                        
      fw.flush();                       
      fw.close();                       
      FileReader fr = new FileReader(file);  
                                        
      size = fr.read(in);               
      System.out.print(size + " ");     
      for(char c : in)                  
        System.out.print(c);
      fr.close();                       
    catch(IOException e) { }
  }
}
9.4.Reader
9.4.1.Chain a line number reader onto a file reader.
9.4.2.Using FileWriter and FileReader
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.