I run the above program in eclipse giving a string as input.
It's creating the file but is not writing into it.
I am not able to understand what is the reason for it?
Thanks
Stuart A. Burkett
Ranch Hand
Joined: May 30, 2012
Posts: 321
posted
0
Try closing your BufferedWriter instance after you've finished writing to it.
your program is fine to me. any error ? where is your output.txt exactly?
Rajiv Rai
Ranch Hand
Joined: Jun 14, 2010
Posts: 57
posted
0
its created in the project root directory after i run the program
Stuart A. Burkett
Ranch Hand
Joined: May 30, 2012
Posts: 321
posted
0
Rajiv Rai wrote:I run the above program in eclipse giving a string as input.
What do you mean by 'giving a string as input' ?
Are you passing a string as a command line parameter or are you typing it in whilst the program is running ?
Rajiv Rai
Ranch Hand
Joined: Jun 14, 2010
Posts: 57
posted
0
I am passing the string as parameter before
running the program using Eclipse run configuration.
So I assume its taken as command line parameter only
Am not giving input whilst the program is running
Stuart A. Burkett
Ranch Hand
Joined: May 30, 2012
Posts: 321
posted
0
Rajiv Rai wrote:I am passing the string as parameter before
running the program using Eclipse run configuration.
So I assume its taken as command line parameter only
Am not giving input whilst the program is running
Command line parameters are passed in the args parameter of your main method.
Trying to read from System.in means your program will read what you type after the program has started.
Rajiv Rai
Ranch Hand
Joined: Jun 14, 2010
Posts: 57
posted
0
Thanks a lot.
Its working now.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32668
4
posted
0
You do not normally need to flush a writer before closing it, as you will see here.
Rajiv Rai
Ranch Hand
Joined: Jun 14, 2010
Posts: 57
posted
0
@ Campbell
As suggested by you.. I omitted the call to flush()
and instead just closed the BufferedWriter instance
I expected the characters to be written to the file
but that is not the case
Here is the code
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.