3 Replies - 475 Views - Last Post: 17 November 2011 - 03:20 AM Rate Topic: -----

#1 vvkavaj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-October 11

help with BufferedReader(not able to understand this prog)

Posted 17 November 2011 - 02:28 AM

import java.io.*;

public class TestBufferedStreams {
    public static void main(String[] args){
    try{
        FileReader input = new FileReader(args[0]);
    BufferedReader bufInput =new BufferedReader(input);
            FileWriter output = new FileWriter(args[1]);
    BufferedWriter bufOutput =new BufferedWriter(output);
    String line;
    line=bufInput.readLine();
    while(line!=null)
    {bufOutput.write(line,0,line.length());
     bufOutput.newLine();
     line=bufInput.readLine();
    }
    bufInput.close();
    bufOutput.close();
    }
    catch (IOException e)
    {
    e.printStackTrace();
    }
    }
    
}



Is This A Good Question/Topic? 0
  • +

Replies To: help with BufferedReader(not able to understand this prog)

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: help with BufferedReader(not able to understand this prog)

Posted 17 November 2011 - 02:39 AM

What you do not understand in that program? Did you write it for your self? Which line of code you have problem with?
Was This Post Helpful? 0
  • +
  • -

#3 vvkavaj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-October 11

Re: help with BufferedReader(not able to understand this prog)

Posted 17 November 2011 - 02:44 AM

Im learning about BufferedReader. I got that code from a friend. I dint understand the FileReader and writer part with the args[0] & args[1].
Was This Post Helpful? 0
  • +
  • -

#4 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1820
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: help with BufferedReader(not able to understand this prog)

Posted 17 November 2011 - 03:20 AM

args is an array of String passes to a main() method from a command line. So when he say args[0] means the first argument in the array passed. FileReader is a class in the same package as BufferedReader, java.io. This class has a constructor that passes a file name as a string and creates a new file reader to the file specified:
FileReader input = new FileReader(args[0]);

Then, BufferedReader has a constructor that passes Reader to read from:
BufferedReader bufInput =new BufferedReader(input);

That means when this program run, you will put file name to read and file name to write as arguments.
You will need to get aware of passing arguments and then read file reader.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1