Writing directly from the Windows command line to a file might not be something you need to do very often. The famous black and white console is better suited to serving system commands and file operations than being a stand-in for notepad. However, it is sometimes useful to have the option of writing multiple lines of text to a file directly from the trusty prompt.
Method One
This is suitable for creating/overwriting a file with multiple lines of text.
copy con SOME_FILE.txt
Type your text here
You can even have multiple lines!
When finished, press CTRL+Z to confirm your action (or CTRL+C to cancel) and ENTER.
If you want to append some text instead of overwriting it completely, follow as above but using:
copy SOME_FILE.txt + con
Method Two
Open up the command prompt and type:
echo SOME TEXT > SOME_FILE.txt
This method creates/overwrites SOME_FILE.txt with the text you entered before the >
. It is only suitable for entering a single line of text into a file.
As with method one, it possible to append text using >>
instead of >
in the command.
Thanks a lot. This command is not new for me because I’m deling with solaris and linux but I nevar thought this will work with windows. Anyway thank you!!
Lalithssm
Thank you very much for your input, as I am new to this could you please suggest me some command to stop the writting in file. I want to use this iin batch file. Thank you.
Regards
Vinay
but if i want to do this
if(a>5) >> SerialMain.java
i can’t bacause
if(a>5) >>
^ ^^
he wreite “if(a” in a file called “5) >>”
help me xD
Thank you very much for the help.