开发者

java code for reading text

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 he开发者_C百科lp me out.

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


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 ""


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().


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜