File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes FileIO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "FileIO" Watch "FileIO" New topic
Author

FileIO

sumit kothalikar
Ranch Hand

Joined: Apr 15, 2010
Posts: 91

//Date 22/06/2010
Programmer : Sumit Kothalikar


line 1 writes the quoted text in Shree.txt file
even though the text is read at line 2 it worksout to be that s is null at line 3 and
there is no output
my question is why s becomes null at line 3 what should be done to read Shree.txt file


Thanks & Regards
Sumit Kothalikar
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Line 1 writes your text to the BufferedWriter - not the file. You need to call flush() and/or close() to write the text to the file. Then you can read it. Try moving bw.close() to just after line 1.
sumit kothalikar
Ranch Hand

Joined: Apr 15, 2010
Posts: 91



Sir,
I did it as you said in line new but the program goes into infinite loop after running the above code.
I can't understand why is it happening so.
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
You are initializing s properly but not updating it in your loop so s is never being set to null. Try adding

to your while loop.
sumit kothalikar
Ranch Hand

Joined: Apr 15, 2010
Posts: 91


I changed the while code at line 3
but now it doesn't print anything.
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
I think we've now fallen into the trap where you ask a follow-up question without first thinking it through yourself. Your problem now is not a misunderstanding about how an API works. It is a simple bug in your code.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
Never do this:

You simply must handle IO exceptions; at least print a message to the log or system out so you know something bad happened.


Ping & DNS - my free Android networking tools app
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Let's help him



Check this....


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
sumit kothalikar
Ranch Hand

Joined: Apr 15, 2010
Posts: 91




Never do this:

catch(IOException e){}


catch(IOException e){} }
You simply must handle IO exceptions; at least print a message to the log or system out so you know something bad happened.



Yes i got it what you want to say Sir
i will always include a System.out.println(e) statement in catch block to through the exception.

But please tell me is there any bug in my code
i am not getting why it is not printing the text which i am writing to the file Shree.txt.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

sumit kothalikar wrote:
I changed the while code at line 3
but now it doesn't print anything.


Try this code, I made a correction,



Clue: readLine() method read& returns the next line in your text.
sumit kothalikar
Ranch Hand

Joined: Apr 15, 2010
Posts: 91

thank you Abimaran Kugathasan Sir
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

No need of Sir!
sumit kothalikar
Ranch Hand

Joined: Apr 15, 2010
Posts: 91

ok thanks Abimaran
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FileIO