tags:

views:

81

answers:

3

i need a sample code for this

if text file is not empty then string s = first line of text of the text file.

please help me out.

ok not a homework question i am not looking for the solution just point me to the correct reference material.

+4  A: 

This sounds like homework, do the following and ask about specific problems.

  1. Open the file using FileReader, and wrap that in a BufferedReader
  2. Call ReadLine on the BufferedReader, set the return value to your string.
  3. if any of the above throws an exception, catch it and set your string to ""
nos
A: 

Some hints (because this smells homework and I'm not going to do it for you): decorate a FileReader with a BufferedReader and check BufferedReader#readLine().

Pascal Thivent
A: 

The sun java tutorials have examples and explanations for tasks like this.

The IO Tutorial has a section in the File I/O section called Reading, Writing and Creating Files which looks like what you are looking for

G_A