File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "FILE I/O" Watch "FILE I/O" New topic
Author

FILE I/O

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: 3054
    
  33

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++)
{
System.out.println(Data);
}


Please guide me

>
Abhijeet Sutar
Greenhorn

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
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
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!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FILE I/O
 
Similar Threads
close() method; I/O class chaining
move file A to file B
FileIO
Text File Help
readLine() and read() functionality