Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

FILE I/O  RSS feed

 
Gaurav x Jain
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

output is:- howdy
why the other one(ydowh) not in output. Please help me
 
Mohamed Sanaulla
Bartender
Posts: 3169
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gaurav x Jain
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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++)
{
System.out.println(Data);
}


Please guide me

>
 
Abhijeet Sutar
Greenhorn
Posts: 17
Android Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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



 
Campbell Ritchie
Sheriff
Posts: 53774
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The File#length() method doesn't tell you how many lines you have in your file.
 
Gaurav x Jain
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your help!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!