This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes FILE I/O Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "FILE I/O" Watch "FILE I/O" New topic


Gaurav x Jain
Ranch Hand

Joined: Feb 01, 2011
Posts: 39

output is:- howdy
why the other one(ydowh) not in output. Please help me
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3151

Please UseCodeTags for the source code posted.

Also you need to loop through the entire contents of the file and print them. In your code- You are just getting the first line- readLine()- would read one line. But your file contains 2 lines.

Mohamed Sanaulla | My Blog
Gaurav x Jain
Ranch Hand

Joined: Feb 01, 2011
Posts: 39
Thank you but I try for loop but it still prints howdy. please find the code as below:

/*Reading Stuff*/
FileReader fr=new FileReader(fileObj);
BufferedReader br=new BufferedReader(fr);
String Data=br.readLine();
for(int i=0;i<fileObj.length();i++)

Please guide me

Abhijeet Sutar

Joined: Feb 28, 2010
Posts: 17

For reading the file line by line ,you have to use BufferedReader.readLine() method which returns next line text ,if it end of the file (Stream) it returns null
Following is the code for reading data from file

OCPJP 6 93%
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 43389
The File#length() method doesn't tell you how many lines you have in your file.
Gaurav x Jain
Ranch Hand

Joined: Feb 01, 2011
Posts: 39
Thank you very much for your help!!!
subject: FILE I/O
It's not a secret anymore!