This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
and it runs in well manner when i write it on console and write "ok" then it will stop taking input , & will automatically imprinted in to My_FileOutput but there is one problem i am not getting output on separate line ... if i write on console..
to all <--line2
ok <--line 3 after this separate notepad of My_FileOutput.txt created and output will be of "Helloto all ", but i want it on separate line... means:
to all in separate notepad
please help me out ... this is my program(and change the file path):
Thanking to all ... (lets hope my Q is not big to all )
You said "Notepad"? Unlike every other text editor ever written, Notepad only recognizes new-line followed by carriage-return as line endings. And that isn't what you are sending as line endings. So change your program if there is somebody standing behind you with a cricket bat who will whack you if you try to use a different text editor. Otherwise, use a different text editor.
Yes, you are right, that Notepad has this \n and \n\r issue, but I think this problem is with the code, not with the editor.
Since String read by readLine won't end with new line character, and since Amey is not explicitly adding new line character, but writing an array of String to the file, I think file will look same; no matter which editor is used here, right?
Why are you using Streams rather than Readers? Are you dealing with text files? Readers work better than Streams for text files.
Why have you got a 1000-member array? You don’t need to keep those Strings in memory if you are simply writing them to a file. What you want is a writing method; you can read the line and write it to the other file in byte format from inside the same loop.
You can get rid of the break, which I consider awkward, like thisWhy have you got the char for the linefeed character? You appear not to use it. Why did you call it str1?
Why are you not closing your streams? You ought to close them in a finally, or use try-with-resources, which only works in Java7.
If you are simply writing the String as a byte, you are not adding line-end characters, so you will get the output as one continuous line.
Anayonkar Shivalkar wrote:Since String read by readLine won't end with new line character, and since Amey is not explicitly adding new line character, but writing an array of String to the file, I think file will look same; no matter which editor is used here, right?
Yes, after looking at the code I think you're correct. I was misled by this line:
Joined: Oct 13, 2005
I think we all came to that conclusion eventually, but Anayonkar Shivalkar was first.