Opening a File by Name


// opening a file for reading BufferedReader is =    new BufferedReader(new FileReader("file.txt")); // opening a file for writing BufferedWriter out =    new BufferedWriter(new FileWriter("afile.txt"));



In this phrase, we show how you can create a BufferedReader for reading input from a file specified by a filenamein this case somefile.txtand how you can create a BufferedWriter for writing text to an output file specified by name, afile.txt.

It is very easy to open a file by name in Java. Most of the input and output stream and reader classes you will use have an option of specifying the file by name in the stream or reader's constructor.




JavaT Phrasebook. Essential Code and Commands
Java Phrasebook
ISBN: 0672329077
EAN: 2147483647
Year: 2004
Pages: 166

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net