The Bash command for what you're trying to do is:

javac -help 2> file.txt

because you're actually redirecting the stderr in this case.